Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Randomness and repeatability

Author
Message
Beta1
23
Years of Service
User Offline
Joined: 28th Dec 2002
Location:
Posted: 15th May 2003 17:51
Sorry not a Jane Austin novel but a question on the random nunmber generator.

I understnad that the RND comand does not generate "truely" random numbers but effectively produces a list of pregenerated random numbers that can be modified(?) by the Randomise command.

So if thats true if I seed the generatot with the same value will it always generate the same series of ramdom numbers each time I run the programs and will it generate the same series of numbers of any computer?

I ask because I have written a semi-random landscape generator based on positioning random peaks on a flat matrix then averageing out the matrix to form smooth hills (then repeat until happy). If I can be sure the random numbers are the same every time I can avoid having to load or save these matrixes and simply regenerate them on the fly from a series of seed values. (eg level 1=seed with 3874593, level 2, 297592 etc.)
Rob K
Retired Moderator
23
Years of Service
User Offline
Joined: 10th Sep 2002
Location: Surrey, United Kingdom
Posted: 15th May 2003 17:57 Edited at: 15th May 2003 19:20
If you do want random numbers Use RANDOMISE TIMER() this seeds the Rnd function with the timer, which changes 1000 times / second.

The random numbers are calculated according to a special number defined by the makers of the programming software, certainly for Visual Basic and Visual C++, according to my text books for both of them.

[Edit: Didn't read the question. Sorry!]

Do you want Windows menus in your DBP apps? - Get my plugin: http://snow.prohosting.com/~clone99/downloads/tpc_menus_102.zip
BatVink
Moderator
23
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 15th May 2003 18:18 Edited at: 15th May 2003 18:18
I think the answer to your question is YES, the random set of numbers is the same for every computer.

I don't know if this is held in the BIOS or CPU. I also don't know if the random numbers stay the same across different manufacturers (Intel/AMD for example).

I just tested it on 2 Intel machines (P3 850, mobile Intel and a P3 1Ghz Standard chip) and they both gave the same set of numbers.

Run this code from an Office application and check the debug Window. See if you get the same results. Perhaps some kind person with an AMD chip will run it too.

Code:

Public Function test() As Integer

For n = 1 To 100
x = x + CStr(Format(Rnd(n * -1), "0.00")) + " : "
Next n

Debug.Print x

End Function


My results...

0.22 : 0.71 : 0.96 : 0.21 : 0.84 : 0.46 : 0.09 : 0.70 : 0.52 : 0.33 : 0.14 : 0.95 : 0.77 : 0.58 : 0.39 : 0.20 : 0.11 : 0.02 : 0.92 : 0.83 : 0.73 : 0.64 : 0.55 : 0.45 : 0.36 : 0.27 : 0.17 : 0.08 : 0.98 : 0.89 : 0.80 : 0.69 : 0.65 : 0.60 : 0.55 : 0.50 : 0.46 : 0.41 : 0.36 : 0.32 : 0.27 : 0.22 : 0.18 : 0.13 : 0.08 : 0.04 : 0.99 : 0.94 : 0.90 : 0.85 : 0.80 : 0.75 : 0.71 : 0.66 : 0.61 : 0.57 : 0.52 : 0.47 : 0.43 : 0.38 : 0.33 : 0.29 : 0.24 : 0.19 : 0.17 : 0.15 : 0.12 : 0.10 : 0.07 : 0.05 : 0.03 : 0.00 : 0.98 : 0.96 : 0.93 : 0.91 : 0.89 : 0.86 : 0.84 : 0.82 : 0.79 : 0.77 : 0.75 : 0.72 : 0.70 : 0.68 : 0.65 : 0.63 : 0.61 : 0.58 : 0.56 : 0.54 : 0.51 : 0.49 : 0.47 : 0.44 : 0.42 : 0.40 : 0.37 : 0.35 :

Thanks in advance.
All the Best,
StevieVee
Beta1
23
Years of Service
User Offline
Joined: 28th Dec 2002
Location:
Posted: 15th May 2003 19:12
Cheers Steivee. I dont have multiple machines to test it on at the moment so that helps a lot. Also saves me having to write my own generator.

As an aside it turns out that the 8 galaxies in the original elite were each randomaly generated using a fibonacci sequence based on a single number. Even then they thought that the 8 numbers occupied too much space on 80s era computers so they used 1 number for galaxy 1, then moved the bits forward one position (wrapping the first to be the last) for the second galaxy and so on. Brilliant way of doing it and so much more elegant than having enourmous pregenerated data files to load in.

Have to see how I can use this on my generator - maybe try and do a "complete world in 20 lines" version

spooky
23
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 15th May 2003 19:14
At work at moment but tested on P3 500 running Windows NT (yuk!).

Get same numbers.

Will test on P4 and Athlon XP when I get home

Gronda, Gronda
Beta1
23
Years of Service
User Offline
Joined: 28th Dec 2002
Location:
Posted: 15th May 2003 19:26
cheers guys.

Mentor
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 15th May 2003 19:48 Edited at: 15th May 2003 21:21
I tried this with a multiplayer test that created random levels and all I had to do was set the random number generator to the same value on the host and remote computer to get the same levels, worked on several machines, ask Programmerholic for the source (I don`t keep my source), we tested on our machines and they are totaly different homebuilds, but we got the same maps and textured blocks in levels made on two computers when all they shared was the same seed over the net, cheers.


Mentor.

APEXnow
Retired Moderator
23
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 15th May 2003 19:54
I thought the random number generator was apert of the Windows Kernel, hence it should be the same for all systems running Windows. I need to check this in MSDN though I do remember reading an article about the Random Number Generator.

"Man who looses key to woman's appartment...... He get no nookie" - A wise chinese man.
MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 15th May 2003 19:59
No, the random number generator is part of C libraries, not the OS...

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
APEXnow
Retired Moderator
23
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 15th May 2003 20:02
Yeah but what was Windows compile in?

"Man who looses key to woman's appartment...... He get no nookie" - A wise chinese man.
APEXnow
Retired Moderator
23
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 15th May 2003 20:02
Well yeah, ok, that's academic, but either way, the numbers should still be the same across systems.

"Man who looses key to woman's appartment...... He get no nookie" - A wise chinese man.
Rob K
Retired Moderator
23
Years of Service
User Offline
Joined: 10th Sep 2002
Location: Surrey, United Kingdom
Posted: 15th May 2003 20:31
As long as you use the same program. It depends what you compile it in, GCC, Visual C++, VB programs will probably all generate different random numbers. However, I am not sure about DBPro as it probably uses the rnd() function from the Visual C++ libs.

Do you want Windows menus in your DBP apps? - Get my plugin: http://snow.prohosting.com/~clone99/downloads/tpc_menus_102.zip
Zed
23
Years of Service
User Offline
Joined: 20th Sep 2002
Location:
Posted: 15th May 2003 20:51
DBP & DB1.?? both use the same randome number generator and produce the same on Intel & AMD CPUs. I use the method to produce the 100,000 solar systems in the Astro Trader game I'm working on.

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 15th May 2003 20:54
I don't actually think it does - the VC++ random numbers are a bit too limited for general use.

You can create your own anyway. I was quite suprised how easy it was when I did it using standard DBPro commands.
Andy Igoe
23
Years of Service
User Offline
Joined: 6th Oct 2002
Location: United Kingdom
Posted: 15th May 2003 21:32
I've been doing this for ages in my Terrascape system, the random number sequence is the same each time on all computers.

Pneumatic Dryll
MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 15th May 2003 21:36
Windows make be compile in C (parts of it anyway), but there is no API command to generate random numbers, hence its not part of the OS.

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
APEXnow
Retired Moderator
23
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 16th May 2003 04:14
The following formulae is used by MS for random number generation.

x1 = ( x0 * a + c ) MOD 2^24

In the above example, the variables are equal to the following assignments

x1=new number
x0=previous number
a=214013
c=2531011

I can't explain anymore otherwise I will violate copyright descriptions used by MS, so figure it out

"Man who looses key to woman's appartment...... He get no nookie" - A wise chinese man.
BatVink
Moderator
23
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 16th May 2003 15:28
Historically, the reason for there being 32,000 seeds is because 32K of ROM was dedicated to a random number table.

Thanks in advance.
All the Best,
StevieVee
Rob K
Retired Moderator
23
Years of Service
User Offline
Joined: 10th Sep 2002
Location: Surrey, United Kingdom
Posted: 16th May 2003 17:11
The CPU has nothing to do with the random numbers generated.

Do you want Windows menus in your DBP apps? - Get my plugin: http://snow.prohosting.com/~clone99/downloads/tpc_menus_102.zip
Mentor
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 16th May 2003 20:59 Edited at: 16th May 2003 21:16
[quote]Historically, the reason for there being 32,000 seeds is because 32K of ROM was dedicated to a random number table.

nope!, not even warm! , take the guys banna off him , the reason for there being 32767 random numbers was the way the algorithm that creates random numbers "wrapped round" after so long, nothing to do with ROM, many 8 bit computers had way less than 32k for the whole OS and provided just as many random numbers, all that happened is the methods used to create random numbers on the old 8 bit machines where carried over to the PC, why invent a new system for creating random numbers when the old one works perfectly well?.


Mentor.

PS wanna generate a "random" sequence?, just take two numbers and start adding, and discard any part that goes over (say) 100, like this.....

32 + 64 = 96 ***32 and 64 are the start numbers****

64 + 96 = 160 discard anything over 100 gives 60

96 + 60 = 156 (56)

60 + 56 = 116 (16)

56 + 16 = 72

16 + 72 = 88

72 + 88 = 160 (60)

88 + 60 = 148 (48)

etc........

different pairs of seeds give sequences that repeat after differing amounts of time, you are not limited to numbers between 0 and 100, any range can be used, cheers.

Mentor.

Login to post a reply

Server time is: 2026-07-11 12:03:14
Your offset time is: 2026-07-11 12:03:14