Re: Yet more random number woes!
Re: Yet more random number woes!
- Subject: Re: Yet more random number woes!
- From: "b.bum" <email@hidden>
- Date: Sat, 12 Jun 2004 20:04:16 -0700
Begin forwarded message:
On Jun 12, 2004, at 8:18 PM, April Gendill wrote:
AHH! I'm ripping my hair out.
ok.. I finally got it to where my random number generator generates
the same numbers in the same sequence every time for any given seed.
but if I switch from 10.3.4 to 10.2.3 the results are COMPLETELY
different which leads me to believe that the results are different on
every computer on the planet. this is a huge problem. Is there a way
to lock down the results so that I get the same number on all
machines?
The man page for random/srandom indicates that the only time the
sequence of numbers generated by one or the other will be the same is
if you pass 1 as the seed. Since it doesn't explicitly mention any
kind of cross-architecture or cross-platform consistency of this
behavior, it probably won't due for your needs.
Unfortunately, it doesn't look like any of the random number sources on
the system (there are several on any Unix derived system) are really
intended to predictable generate a pseudo-random sequence that is
consistent for any given seed.
So... looks like you'll have to roll your own. Fortunately, there are
a plethora of random number algorithms & implementations available for
free. A Google search will likely turn up what you need. You will
be looking for a random number generator that does not "leverage"
rounding error or other similar features and one that uses the seed and
nothing but the seed as the source of the "random" sequence.
+Numerical Recipes in C+ is always a good place to start, though be
forewarned that some of the contained algorithms may be buggy or
sub-optimal.
On Jun 12, 2004, at 7:44 PM, Darkshadow wrote:
Um...I don't have a solution, but doesn't this go against the idea of
random numbers? If you're trying to get the same set of numbers,
couldn't you just use the same set?
Actually, identical sequences of pseudo random numbers across multiple
instances of an application is a very common problem in the gaming
world. Any game that offers competitive play where all players play
on the same "playing field" where the field is randomly generated will
typically just save the seed and then base game events and the
playfield on values encountered in the pseudo-random number stream.
It is also common to find games that will save the random number seed
as a part of save games so that you can effectively replay any given
game. For example, a solitaire game could save a single 32 bit value
as the random seed and base all shuffling events off of that seed. As
a result, no matter how the player plays a game, the same sequence of
card state changes will always cause the same sequence of cards to come
up, even though the order of cards is effectively random.
b.bum
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.