Shoutbox

Random Number Generation - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: Random Number Generation (/showthread.php?tid=65177)

Random Number Generation by M73A on 08-21-2006 at 12:03 AM

what i dont understand is how it works, how is anything with a computer random? there must be some sort of code or whatever which decides the number, it cant just be plucked out of thin air... can it?


RE: Random Number Generation by user27089 on 08-21-2006 at 12:20 AM

It can probably just pick a random number, there wouldn't be a line of numbers that the computer slowly moves down.


RE: Random Number Generation by surfichris on 08-21-2006 at 12:25 AM

They're not true random numbers as you said.

There is a good overview about it all at http://www.random.org/essay.html

And also: http://www.robertnz.net/true_rng.html


RE: Random Number Generation by CookieRevised on 08-21-2006 at 02:17 AM

Put this VB6 code in a module and run it, you'll see that the random numbers aren't in fact random. The code will generate each time the same "random" numbers.

code:
Sub main()
  Dim I As Long
  Dim List As String
  For I = 1 To 10
    List = List & Rnd & vbCr
  Next I
  MsgBox List
End Sub
This is what they mean with "pseudo-random" numbers, and that you can predict which number will be taken as 5th in the list for example.

(for VB, and extremely many other languages, this is because each successive call to the Rnd function uses the previous "random" number as a seed for the next number in the sequence)



------

To make this less "pseudo-random" (at least to the outside), you set a different seeding (or starting point if you will) for the list.

eg:
code:
Sub main()
  Randomize Timer
  Dim I As Long
  Dim List As String
  For I = 1 To 10
    List = List & Rnd & vbCr
  Next I
  MsgBox List
End Sub
Now, the list will be different each time because you pick a different seeding each time. This is done by basing the seeding on the Timer value (which changes every millisecond).

This is, sort of(!), what they mean with the "source of entropy".


The randomizing of the seeding isn't done automatically because a fixed sequences of pseudo-random numbers does have its uses also.


------

As for experiment try to replace the 'Timer' with a number of your choice and run the routine again a couple of times...
RE: Random Number Generation by Bolter99 on 08-21-2006 at 03:06 AM

Computers uses the system cloc to generate random numbers. Its passed through a formula that leaves just one number between 0 and 1 that can then be multiplied to make a number between it and 0.

eg.

0.8678289757574522 x 10 (this will be your maximum) = 8.678289757574522

round it down then and your left with 8.

The bold number was randomly generated.


RE: Random Number Generation by Adeptus on 08-21-2006 at 03:33 AM

quote:
what i dont understand is how it works, how is anything with a computer random? there must be some sort of code or whatever which decides the number, it cant just be plucked out of thin air... can it?
In most cases you are correct and the numbers are only pseudo-random.  That is certainly true of standard random number functions of most programming languages.

However, it doesn't have to be so.  Truly random numbers can be generated by specialized hardware (usually using Gaussian noise from a semiconductor junction).  Intel motherboard chipsets, starting with i810 released in 1999, contain such hardware and provide a standartized interface to it. 

The Intel hardware random number generator is supported by Linux kernel as entropy source for /dev/random and /dev/urandom devices.  Most Linux applications use these devices to obtain random numbers, so they  benefit from the hardware random number generation when running on machines using Intel chipsets, without the application programmers having to do anything special.  These random numbers are truly random.

It is also possible to build pretty good entropy by accumulating data like timing between keystrokes, mouse movements, and the durations of disk I/O requests.  While not random in the strictest of senses, the sequence and timing of such events is virtually impossible to predict or reproduce, especially on modern multi-tasking systems running several apps at once.


RE: Random Number Generation by M73A on 08-21-2006 at 09:29 AM

hm, ok thanks :d i asked because i was in maths and the Rnd key on my calculator was bugging me it seemed random but i didnt want to believe it!


RE: Random Number Generation by CookieRevised on 08-21-2006 at 10:20 AM

quote:
Originally posted by Bolter99
Computers uses the system cloc to generate random numbers.
Actually not true.

By default they do not use the system clock, you can make them use it like I showed in my previous post, but they do not by default.

The links posted by Chris Boulton explain it all in great detail.