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.

Geek Culture / Random Number Generator

Author
Message
Chris K
20
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 22nd Dec 2003 13:15 Edited at: 22nd Dec 2003 13:15
This a question to Rich really but someone else will surely know... how does the rnd() command in DB work?

I was think about this yesterday and I decided there was no way of making a truely random number. In a book I've got (The Code Book) it says that one of the only random things in the universe is the radioactive decay of some elements (!?)

The only way I could think of faking it would be to base it on factors that seem unrelated - mouse x/screen fps()*CPU temperature ....

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 22nd Dec 2003 13:19
It uses the function provided by Microsoft. I can't say exactly which system it uses (I could guess) and it only has a range of 0 to 32767. I have a much larger ranged system somewhere ...

It's true that there are no truly random numbers, but in code, there are random numbers that are 'good enough'. It's something that only statisticians lie awake at night over

For free Plug-ins, source and the DBPro Interface library for Visual C++ 6 and .NET
http://www.matrix1.demon.co.uk
OSX Using Happy Dude
21
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 22nd Dec 2003 13:32
Its best to base any random number generator on hardware things like you mention. In addition extra bits can be used : HD Serial number, processor speed, GPU info etc.


The place for all great plug-ins
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 22nd Dec 2003 14:11
The sequence is not random, because if you start at the same seed each time, the random numbers repeat over and over.

A good way to get a nice random number that is unlikely to repeat itself is this little function:

Function RealRND(Range)

Randomize Timer()
RealRND=rnd(Range)

Endfunction RealRND


Each time it needs a new random number, it generates the seed first so that each number is more random because the seed is based on a constantly changing value.


Van-B


Next time he runs past, GRAB HIM!
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 22nd Dec 2003 14:53
Randomize Timer() takes the clock pulse 60th sec, and performs some mathematics on it to give you a random number. That's what most games do.

Pincho.
Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 22nd Dec 2003 23:11
you could record some sound for a few seconds and then make it a memblock, you should see some low value numbers in the file that are the thermal noise in the audio circuits, that should be about as random as you could get and changes rapidly over time unlike the cpu temp (I was gonna post a snippet but DB complains the sound object number doesn`t exist when I tried....I know that stoopid compiler!...I`m trying to make one!...duh!).

Mentor.

System spec : Pentium 3.0Ghz, 512MB DDR, 1x160Gb HD (using 2 overheats ), DVD RW/CD RW (all modes), multimedia front panel, 6 way surround sound, ATI radeon 9800 128mb.
Fallout
22
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 22nd Dec 2003 23:34
As I've been led to believe, there is an array of random number seeds, from 0 to 32767, as mentioned by Ian M. Rnd() just references the next number in that seed. The default seed used is 0 (probably) and therefore the same numbers will be generated every time you use rnd() unless you choose a different seed. Randomize Timer() simply uses the amount of milliseconds (or whatever unit) has elapsed sinse midnight to choose which of those seeds to use.

Insiiiiiiiiiiiiiiiiiiiiiiiide!
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 22nd Dec 2003 23:47
It's not an array.

It basically applies a calculation to the last number it generated to generate the next value returned (and its next seed value).

For free Plug-ins, source and the DBPro Interface library for Visual C++ 6 and .NET
http://www.matrix1.demon.co.uk
Shadow
21
Years of Service
User Offline
Joined: 17th Oct 2002
Location: In the shadows
Posted: 23rd Dec 2003 00:37
Random numbers are generated by applying a formula.

You choose a number to start with, then do something to it to get the first random. Do the same thing to that to get the second, then again to get the third, etc.

Martyn Pittuck
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 23rd Dec 2003 09:38
Although with the help of quantum computing you can very easily get a true random number gernerator!!

The particles in quantum computing have 3 states, on/off/middle (To keep things simple). Scientists can make these particles go to any of the states, but when trying to measure the state of a particle they turned middle the particle randomly switches to on/off state, making a truly random random number gernerator.

Web Design Starting from $200. Special limited offer. MSN or Email me for more information.
Chris K
20
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 23rd Dec 2003 10:37
Quantum Computers will almost certainly not work. If they do, though, they will be able to break any code instantly.

Apart from Quantum Cryptography, which has been proven to be unbreakable.

Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 23rd Dec 2003 17:03 Edited at: 23rd Dec 2003 22:19
simple (psuedo) random number generator

take two numbers

12
34

add

46

add 46 to last number (34)

80

add 80 to 46 (and discard any values over 100)

126=26

6

32

38

70

108=8

78

86

164=64

150=50

114=14

64

78

142=42

etc

this gives a more or less random number sequence that repeats every so often, how often it repeats is down to the values in the two starting seeds IIRC, if you want to try this out then here is the code to play with this simple algorythm



cheers.

Mentor.

System spec : Pentium 3.0Ghz, 512MB DDR, 1x160Gb HD (using 2 overheats ), DVD RW/CD RW (all modes), multimedia front panel, 6 way surround sound, ATI radeon 9800 128mb.
Wik
21
Years of Service
User Offline
Joined: 21st May 2003
Location: CT, United States
Posted: 23rd Dec 2003 20:23
or you could put a lump of clay in a time excellerator and measure its radioactive decay.


Ian T
22
Years of Service
User Offline
Joined: 12th Sep 2002
Location: Around
Posted: 23rd Dec 2003 22:47
Put a mouse in a box, wire stuff up to its brain, show it five constantly changing movies at a time, and get the random number from the content of its brain waves.

--Mouse: Famous (Avatarless) Fighting Furball

A very nice %it, indeed.
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 24th Dec 2003 04:17
Really, I just want some ball bearings falling down between pins. Too much to ask?

Pincho.
Arrow
21
Years of Service
User Offline
Joined: 1st Jan 2003
Location: United States
Posted: 24th Dec 2003 09:06
The old numbers on the wall with a blindfolded dart thrower allways works.


I've lost 25lb playing Dance Dance Revolution, no really!
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 24th Dec 2003 15:17
How would you score 'floor' or 'bystander'?

For free Plug-ins, source and the DBPro Interface library for Visual C++ 6 and .NET
http://www.matrix1.demon.co.uk
Chris K
20
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 24th Dec 2003 15:25
Doesn't work like that. The point is they only have one photon being produced at a time. Therefore it can't make a shadow.

Still.... if you can find a way, you're a rich cup of coffee.

Arrow
21
Years of Service
User Offline
Joined: 1st Jan 2003
Location: United States
Posted: 24th Dec 2003 16:48
Hitting the floor mulitplies the next number by 10, if you hit the floor again it stacks (aka it become 100, then 1,000 ect).

Hitting bystanders will crash the system, and most likly the dart thrower will crash too, probably through a plate glass window.


I've lost 25lb playing Dance Dance Revolution, no really!

Login to post a reply

Server time is: 2024-09-21 01:43:21
Your offset time is: 2024-09-21 01:43:21