Random Numbers

Blitz3D Forums/Blitz3D Beginners Area/Random Numbers

_PJ_(Posted 2010) [#1]
Further to other discussions on the pseudo-random algorithms and concept of seeding the randomiser, is there any guarantee of, or means to guarantee that when a specific seed is set, that different CPUs will return the same sequence without fail?

For example:
the following code and the results I get:
SeedRnd 3
For n=0 to 9
Print (Rand(9))
Next
; 2 1 4 9 9 3 2 8 7 3


Has anyone or might anyone ever get different results?


GfK(Posted 2010) [#2]
The only time I've ever seen different results, was between Blitz3D and Blitzplus running identical code. There are a small number of people who will tell you otherwise. All I can say is I've never seen it.

The best solution is to not use native Rand/Rnd. There was a mersenne twist userlib doing the rounds a couple of years ago so you might want to have a dig for that. That guarantees identical results on different PCs.


puki(Posted 2010) [#3]
I ran it and got the same: 2 1 4 9 9 3 2 8 7 3.


_PJ_(Posted 2010) [#4]
Thanks both of you, I'l check that out, GfK. I guess best to be safe than sorry!


Yasha(Posted 2010) [#5]
I too get the same results.

As far as I can see, a basic Blitz3D application only imports user32.dll and kernel32.dll. I don't think either of those supplies any random number generation features, so wouldn't that imply that the code to generate random numbers is 1) part of the B3D library and therefore 2) consistent across machines?


Matty(Posted 2010) [#6]
It is very easy to make your own random number generator, there are plenty of algorithms on line...can't remember where to find them but they are not too hard to implement.


_PJ_(Posted 2010) [#7]
I too get the same results.

As far as I can see, a basic Blitz3D application only imports user32.dll and kernel32.dll. I don't think either of those supplies any random number generation features, so wouldn't that imply that the code to generate random numbers is 1) part of the B3D library and therefore 2) consistent across machines?



IF (and I trust your reasoning :) ) that because those dlls (and I checked since you pointed them out, GDI32, ole32 and AdVapi32 too are included, but no commands are used which seem remotely connected to random numbers, so your point is still spot on)
IF that fact does mean that the random number generation is a 'part of blitz' ands therefore (I presume) compiled into the exe, then yeah, definitely that would HAVE to be the same on all machines.

It is very easy to make your own random number generator, there are plenty of algorithms on line...can't remember where to find them but they are not too hard to implement.

Yeah, Ive seen a few over the archives I'm sure, and certainly on some threads in the main programming forums.

Thanks. Overall, I'm even more confident than I was about whatever method Blitz uses, and I havent encountered any problems with it yet. Really I just wanted to double check, just in case.


stanrol(Posted 2010) [#8]
ran it and same as Malice.
Blitz3D.


Canardian(Posted 2010) [#9]
Use this:
SeedRnd MilliSecs()
to get each time different random numbers.


stanrol(Posted 2010) [#10]
and reemember, no indentation for code!


Ross C(Posted 2010) [#11]
For you maybe. Stop forcing the issue on this. Indentation is a god send when debugging code and following it through.


GfK(Posted 2010) [#12]
and reemember, no indentation for code!
I can accept beginners thinking any code they write is the dog's doo dars, but now you're just spamming the forum with mindless crap.

Please stop.


Canardian(Posted 2010) [#13]
@stanrol: Why should code not be indented? You must have a good reason for it, what is it?

Actually when I was younger, I didn't also like how much people indented code, they used like 7 character wide tabs.
I used 3 character wide tabs.
Today I use 4 character wide tabs, because that's also the default in Visual Studio.
BlitzMax has 5 character wide tabs, which is way too much.
Blitz3D has 4 character wide tabs, which is correct.


Kryzon(Posted 2010) [#14]
and reemember, no indentation for code!

Visual structure plays an important role with understanding the flow of a piece of code (like with a chain of conditionals), just like any kind of diagram.

If you don't like to use indentation, then go ahead, discard it.
Just don't preach it as a bad practice like you have been stubbornly doing despite all the [righteous] warnings against that, which you so carelessly seem to ignore.


Yasha(Posted 2010) [#15]
BlitzMax has 5 character wide tabs, which is way too much.
Blitz3D has 4 character wide tabs, which is correct.


Actually in either default IDE, you can hold down CTRL and scroll the mouse wheel to change the tab width.


Kryzon(Posted 2010) [#16]
Come again?!?!?1

how can you know this?

EDIT: I'll be damned. Thanks for the tip Yasha!


_PJ_(Posted 2010) [#17]

Use this:
SeedRnd MilliSecs()to get each time different random numbers.


Lumooja, thanks, but the purpose of the thread, is kinda the opposite. I want a means to gurantee a pseudo-randomised list that would only be dependant on the seed passed. Read my initial post again :)

Anyway, I think I'm safe with B3D'a SeedRnd!


and reemember, no indentation for code!


I think I've only ever heard the opposite, from professionals, tutors and in books etc. Your post is also spammy and bears no relevance to the thread.