Pseudo-random reproducible number generator?

Blitz3D Forums/Blitz3D Programming/Pseudo-random reproducible number generator?

WarpZone(Posted 2005) [#1]
Hey. I'm looking to devise a way of getting a list of numbers that looks random, but which returns the same list every time it is run.

I'm a little unsure how the rnd and rand commands work. Do they rely upon some sort of bank of numbers that is burned into a chip somewhere on the motherboard, coupled with whatever number you seed it with? (Usually milliseconds.)

The reason I ask is because I need a reliable way to make stuff LOOK random but not actually BE random. One method I considered is this:

SeedRnd 1 
For x=1 To 10
num=Rnd (10)
Print num
Next


When I run this on my computer, it ALWAYS produces the same 10 numbers. BUT. I don't just want it to do this on my computer. I want a program that will produce the same ten numbers on EVERYONE'S computer.

If BlitzBasic's random number generator draws non-seed variables from internal code, then this code (when compiled into an exe) should produce the exact same output on every computer it's run on.

On the other hand, if it hashes the seed number with a list of numbers on a chip, then each computer model will work differently. It means that some computers will return the same "random" numbers as my computer, while other brands or models of computer parts will do all kinds of different things with that "SeedRnd 1" command.

Can anyone tell me whether Blitz's random numbers are software-encoded or derived from hardware on the computer?

And would somebody please run the above code and tell me what numbers the program outputs. On my computer, it's always:

3
7
9
7
0
2
3
1
1
6

If we all get the same numbers from "SeedRnd 1," then it means it'll be easy to do what I want to do. If not... :/ Then I'll have to write my own txt file full of "random" numbers and figure out how to hash it manually.

Thanks in advance for your help! :)


morduun(Posted 2005) [#2]
Blitz's PRNG is broken for this purpose (known issue, current behavior will not be changed) and for encryption as it depends on the FPU, and float results will vary noticeably across processors. I recommend Kanati's excellent Mersenne Twister userlib for this purpose, which can be found here:

http://www.blitzcoder.com/cgi-bin/showcase/showcase_showentry.pl?id=kanati886903202005194825&comments=no


Rook Zimbabwe(Posted 2005) [#3]
I got
3
7
9
7
0
2
3
1
1
6
and then 3.14152798963021 (OK I didn't get that PI thing...) but I did get your list exactly as you did. If you seedrnd 1 you will always get the list for 1... (now your test is a BIT small!) I am running an Athlon 64 3200+... it could be on a larger assignment of random numbers there might be slight variations in the stream... but only possibly at a TRULY HUGE count of variables....


RGR(Posted 2005) [#4]
If you want Random INTEGERS you should at least use Rand
Rnd produces Floats...


WarpZone(Posted 2005) [#5]
Well, now I've tried it on one other computer besides this one, so far, besides the feedback from Rook. That's 3 computers that all generate the same table of numbers.

morduun, are you saying that you are definitely sure there are differences across processors, and that the results Rook and I have gotten so far are a coincidence? (I.E. same table in the processor?) Or are you only talking about floats with decimal places? Would my code work as planned (E.G. same integers on all computers regardless of processor) if I replaced rnd with rand?

I will definitely take a look at that userlib. Sounds interesting, and relevant to my project.

I'm still uncertian how this actually works, so please keep posting here, folks. Especially if you managed to generate a different batch of numbers! :) Thanks.


RGR(Posted 2005) [#6]
WarpZone, I tested Blitz Random on several computers - I found no errors yet - the rows where everywhere the same.
btw - your code produces the same numbers here... although your floating point numbers get changed to integers


WarpZone(Posted 2005) [#7]
Incidently, what's up with my 5-line, no-graphics application taking up 1.23mb? :( I was sort of expecting Blitz to compile down a little bit better than that.


Andy(Posted 2005) [#8]
>morduun, are you saying that you are definitely sure there
>are differences across processors, and that the results
>Rook and I have gotten so far are a coincidence?

B3D's RNG is broken, in that you can't rely on the result being the same across a number of different platforms. This is old news.

>Incidently, what's up with my 5-line, no-graphics
>application taking up 1.23mb? :( I was sort of expecting
>Blitz to compile down a little bit better than that.

B3D appends the entire B3D commandset to the exe, even if you just use a single command.

Andy


WolRon(Posted 2005) [#9]
Just create a 10K file filled with random numbers (Blitz can generate them for you). Then just load/use those values in all of your 'random' statements. This is the process I used for a 'predictable' casino game.


morduun(Posted 2005) [#10]
Yes, I am definitely certain. As Andy indicates, this is a known, beaten to death and now ancient issue that BR is aware of and has decided not to change. Using RND/RAND makes no difference as the core PRNG is based on float values, not integers.

Again, Kanati's Mersenne DLL is excellent and I highly recommend its use for algorithmic content generation and encryption.