[Bmx] Can I rely on Rand function to generate identical sequences?

Started by wookie22, March 24, 2019, 14:51:52

Previous topic - Next topic

wookie22

As Rand is based on floating point operations I'm wondering if giving the same seed I will get the same results on every machine. Anyone know something about it?
Hidden Deep - 2D Action & Exploration Sci-Fi Thriller for PC/Mac/Linux
http://www.hiddendeepgame.com

Yellownakji

Quote from: wookie22 on March 24, 2019, 14:51:52
As Rand is based on floating point operations I'm wondering if giving the same seed I will get the same results on every machine. Anyone know something about it?


If i'm not mistaken, RAND uses the system-clock to generate a number.   I don't think otherwise.

You could create your own seed system.   It's not super super tricky, just time consuming.    Every letter you enter will update one or more variables.  That's how certain games like minecraft handle seeds.

GW

I can't say for sure from my experience, however Bmax has been win/mac/linux from the beginning (2004) and I can't recall issue coming up.

[edit]
I did find a post from 2011[1] where someone claims it's not deterministic and suggests Bruceys random module.  I've replaced the brl random with wtih bruceys random module years ago as it produced better random numbers in general.

[1]http://mojolabs.nz/posts.php?topic=94419

Matty

Here's a random number generator

Look in the functions here.....'seed' is a global variable.

http://www.mattiesgames.com/learntocode/engine/functions.js

Your own deterministic random number generator.....basically same as what VBA in Excel uses (methodology)

col

Rather than everyone guessing the answer why don't we post our results to find out.


Here's some results from test units I have here using the standard BlitzMax 1.50

SeedRnd 1118272

For k=1 To 10
Print Rnd(10.10)
Next


Windows 10 Pro
5.5124371326399269
1.2384022145700284
0.35361654399026321
1.8116738415466080
4.1793979756309891
0.54494589303085272
6.6475921139506013
8.2621353119825383
5.9340719629725021
10.026912050562693

Windows 7 Home
5.5124371326399269
1.2384022145700284
0.35361654399026321
1.8116738415466080
4.1793979756309891
0.54494589303085272
6.6475921139506013
8.2621353119825383
5.9340719629725021
10.026912050562693

Linux 32bit Ubuntu VM
5.5124371326399269
1.2384022145700284
0.35361654399026321
1.8116738415466080
4.1793979756309891
0.54494589303085272
6.6475921139506013
8.2621353119825383
5.9340719629725021
10.026912050562693
https://github.com/davecamp

"When you observe the world through social media, you lose your faith in it."

Derron

Get the very same numbers - yet I am not 100% sure if that happens on every computer because of said FP determinism problem.  As we use "double" here it might already help in most cases when we deal with floats instead (potential loss of accuracy).

Maybe of interest:
https://github.com/bmx-ng/brl.mod/issues/84
-> size of the numbers matters in some cases.


bye
Ron

wookie22

@Col Are all these machines on Intel CPU? I think that processor is important here. Also I think you should made 1mil iterations (just print every 100 000th and the last).
Hidden Deep - 2D Action & Exploration Sci-Fi Thriller for PC/Mac/Linux
http://www.hiddendeepgame.com

col

Quote@Col Are all these machines on Intel CPU?

Hiya,

I used a mixture of CPUs:
Intel i5-4440 - Ubuntu
Intel i7-3610 - Win7, Win10

And I've also just tried with a Ryzen5 2600X on Win10 to use a different chip manufacturer and got the same results.

Are you getting similar results?

Hope it helps.
https://github.com/davecamp

"When you observe the world through social media, you lose your faith in it."

Derron

Mine was run on a linux box containing an AMD processor.


Bye
Ron

wookie22

Thanks for testing. So try that ultimate test on AMD:


SeedRnd(178818223)

Local r:Double
For Local j% = 1 To 1000000
r = Rnd(0, 10)
Next
print r


My result (Intel I3): 3.2892029219375827
Hidden Deep - 2D Action & Exploration Sci-Fi Thriller for PC/Mac/Linux
http://www.hiddendeepgame.com

col

https://github.com/davecamp

"When you observe the world through social media, you lose your faith in it."

wookie22

Hidden Deep - 2D Action & Exploration Sci-Fi Thriller for PC/Mac/Linux
http://www.hiddendeepgame.com