What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » Random Number Generation

Random Number Generation
Author: Message:
M73A
Veteran Member
*****

Avatar


Posts: 3213
Reputation: 37
34 / Male / Flag
Joined: Jul 2004
O.P. Random Number Generation
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?

[Image: lost7ru.gif]
08-21-2006 12:03 AM
Profile E-Mail PM Find Quote Report
user27089
Disabled Account


Posts: 6321
Joined: Nov 2003
Status: Away
RE: Random Number Generation
It can probably just pick a random number, there wouldn't be a line of numbers that the computer slowly moves down.
08-21-2006 12:20 AM
Profile PM Find Quote Report
surfichris
Former Admin
*****

Avatar

Posts: 2365
Reputation: 81
Joined: Mar 2002
RE: Random Number Generation
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

This post was edited on 08-21-2006 at 12:26 AM by surfichris.
08-21-2006 12:25 AM
Profile PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: Random Number Generation
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...

This post was edited on 08-21-2006 at 02:26 AM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
08-21-2006 02:17 AM
Profile PM Find Quote Report
Bolter99
New Member
*


Posts: 7
Joined: Aug 2006
RE: Random Number Generation
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.

This post was edited on 08-21-2006 at 03:11 AM by Bolter99.
08-21-2006 03:06 AM
Profile E-Mail PM Find Quote Report
Adeptus
Senior Member
****


Posts: 732
Reputation: 40
Joined: Oct 2005
RE: Random Number Generation
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.


This post was edited on 08-21-2006 at 03:36 AM by Adeptus.
08-21-2006 03:33 AM
Profile E-Mail PM Find Quote Report
M73A
Veteran Member
*****

Avatar


Posts: 3213
Reputation: 37
34 / Male / Flag
Joined: Jul 2004
O.P. RE: Random Number Generation
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!

[Image: lost7ru.gif]
08-21-2006 09:29 AM
Profile E-Mail PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: Random Number Generation
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.
.-= A 'frrrrrrrituurrr' for Wacky =-.
08-21-2006 10:20 AM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On