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:
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
« Next Oldest Return to Top Next Newest »

Messages In This Thread
Random Number Generation - by M73A on 08-21-2006 at 12:03 AM
RE: Random Number Generation - by user27089 on 08-21-2006 at 12:20 AM
RE: Random Number Generation - by surfichris on 08-21-2006 at 12:25 AM
RE: Random Number Generation - by CookieRevised on 08-21-2006 at 02:17 AM
RE: Random Number Generation - by Bolter99 on 08-21-2006 at 03:06 AM
RE: Random Number Generation - by Adeptus on 08-21-2006 at 03:33 AM
RE: Random Number Generation - by M73A on 08-21-2006 at 09:29 AM
RE: Random Number Generation - by CookieRevised on 08-21-2006 at 10:20 AM


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