Git Product home page Git Product logo

Comments (6)

reubene avatar reubene commented on August 30, 2024

This code is poorly documented, so I'm not really sure. I think the idea of % max-1 is that there are therefore max possible numbers so Next(5) will give five possible results zero through four.

from civ2-clone.

axx0 avatar axx0 commented on August 30, 2024

For Next(5):
max-1 gives 0,1,2,3
max gives 0,1,2,3,4
max+1 gives 0,1,2,3,4,5

Not sure which of the last two is the correct one. I think some other methods in the class have similar issues.

Anyway starting a new game it always chooses Romans from [Roman,Celtic,Russian] civs. For other civs it however seems to chose random, as it should. I'll look into it more.

from civ2-clone.

reubene avatar reubene commented on August 30, 2024

Have you changed the seed? I had the random number generator hard coded to a seed of 1 at one point

from civ2-clone.

reubene avatar reubene commented on August 30, 2024

For Next(5):
max-1 gives 0,1,2,3
max gives 0,1,2,3,4
max+1 gives 0,1,2,3,4,5

Not sure which of the last two is the correct one. I think some other methods in the class have similar issues.

Anyway starting a new game it always chooses Romans from [Roman,Celtic,Russian] civs. For other civs it however seems to chose random, as it should. I'll look into it more.

Looks like the correct behaviour is just max max-1 is definitely wrong

from civ2-clone.

axx0 avatar axx0 commented on August 30, 2024

I tried with a couple of different seeds and there's not much improvement.
Two problems when e.g. generating 100 random numbers with Next(2):

  • the first generated number always seems to be 0
  • there are clusters of zeros and ones

Out of curiosity, why didn't you use the random class that comes with .net?

from civ2-clone.

reubene avatar reubene commented on August 30, 2024

Interesting. After correcting it to use straight max I get:
1073741823 of the possible 2147483647 seed values generate a 1 the others generate a 0 for Next(2)

That's exactly how you would expect Next(2) to behave, it's almost exactly half.

With Next(2) you will always get clusters of zeros and ones as they are supposed to appear independent (It's a pseudorandom number generator so they are not really independent)

I wrote this one, based on an algorithm I found online, because I wanted something that could be serialized easily into a readable format and could be run across languages. This is from a multiplayer implementation of Colonization I was working on a few years ago that had a interface in Typescript and a server in C#

from civ2-clone.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.