Where do Random numbers come from?

Computer Science Teacher
Computer Science Teacher - Thoughts and Information from Alfred Thompson

Where do Random numbers come from?

  • Comments 4

One of the things that gets used and discussed a lot by beginning programmers is random numbers. of course those of us who have been around the block know that computer generated numbers are really pseudo-random numbers. It's a fairly short and reasonable discussion to explain seed values and why the same sequence of numbers will come up if the same seed value is given. But explaining how these numbers are generated is a more complex discussion completely.

Last week Paul Vick of the Visual Basic team posted a note about pseudo-random numbers and Visual Basic. Included in this post is a code example of one version of a random number algorithm written in Visual Basic. It's not an algorithm for the timid and it involves some concepts that many students will not learn in a first course in programming. But I think it is useful even in those cases for students to get a feel for some of the complexities involved in the process.

An other interesting thing in Paul's post is that he discusses the weakness of the Rnd function in Visual basic and why it hasn't been updated. The short story is that they are concerned that there is code out there that relies on a specific seed value generating the same string of numbers and they don't want to break those programs. At the same time there want to provide a stronger, better function for those people who have that sort of need. Balancing the issues of improvement and innovation against backwards comparability makes an interesting discussion to have in class and other places.

  • programs that depend on random numbers not being random? OMGWTFBBQ?!
  • For testing purposes one very often would like a known set of "random" numbers coming up. This lets you make sure that the rest of the algorythm is working correctly. Generally when the code is put into production some additional randomization is put into place by, for example, using the date/time as a seed value. But if you know that one seed gives a specific set of numbers you don't want that to change oout from under you.
  • I need to break a computer generated number system that changes daily. This is a 5 digit number. The first two digits are the current month but the last three change daily.

    On 12/19/05 the code was 12030. I have not been able to duplicate this number. can you help me?     Thanks, Bob
  • There isn't really enough information here for me to even think about trying. One would need a very large data set and more information about where the number comes from and how it is used.
Page 1 of 1 (4 items)