Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Angelina Jolie proves the Randomize function is not random 1

Status
Not open for further replies.

AndyGroom

Programmer
May 23, 2001
972
0
0
GB
For a long time I have suspected that the Rnd() function does not produce truly random numbers. It's a computer after all; doing things randomly is against its nature. A couple of weeks ago I decided to start an experiment to create images by plotting the results of the Rnd() function to see if I could see patterns in the static - a bit like when Jodie Foster stares at the un-tuned TV in the movie Contact. My hunch - I suppose somewhere at the back of my mind - was that someone at Microsoft might, for a joke, have somehow contrived to get the Rnd() function to produce pseudo random numbers based on some non-random sequence (kind of like the Fibonacci sequence but less obvious).

To start off I set a loop seeding the Randomize function with values from 0 to 65,535 and then I plotted the first 65,535 numbers returned by the Rnd() function onto a 256x256 picture box and flashed one up on screen every second. Unsurprisingly most of the results didn't look like anything other than garbage, so instead of working with colour I simplified things and took things back to a binary base, 1s and 0s, plotting black for 1s and white for 0s.

The image below is typical of the output. The decision whether to plot a pixel at this stage was based on whether the first three digits of the Rnd() function was greater or less than 500 (ie. Int(Rnd*1000)>500). (The 27552 in the corner is the Randomize seed value, not part of the results!).

plot1.bmp


I went back and kept tweaking the formula. The image below is based on the same sequence as above (27552) but this time based on (Int(Rnd*100)>50).

plot2.bmp


Can you see it now? I thought I was seeing things when I first produced this image and if you set the seed value to anything other than 27552 you still seem to get garbage, but you can clearly see an image of what seems to be a woman's face. Encouraged by my results and fuelled by quite a lot of vodka I pressed on, each time simplifying the formula and with each simplification I seemed to purify the results. Here is a plot of (Int(Rnd*10)>5):

plot3.bmp


The final breakthrough came with the purest form of the Rnd() function - plotting 1 for even numbers and 0 for odd numbers:

plot4.bmp


And there she is! I'm pretty sure that's Angelina Jolie. Proof that plotting the results of the Rnd() function is far from random. The only remaining puzzle was the significance of 27552 as the seed value but of course, it turned out to be the most obvious thing, the value returned by DateSerial if you pass Angelina's date of birth: 7th June 1975.

I'm sure you think I'm crackers but the proof is incontravertable. If you want to try it for yourself the code is below. All you need is a standard PictureBox on your form. Set the Appearance to Flat and BorderStyle to None, ScaleMode to Pixel and AutoRedraw to True, set the Width and Height to 3840 (which is 256x256 in ScaleWidth and ScaleHeight) then paste the code below into the Form_Load event.

I can sleep now.

Code:
' Set the Rnd() seed to Angelina Jolie's date of birth
Randomize DateSerial(1975, 6, 7)
For Y& = 0 To Picture1.ScaleHeight - 1
  For X& = 0 To Picture1.ScaleWidth - 1
    ' Plot a point if the Rnd() function returns an even number.
    ' If you plot odd numbers the image will be negative (white on black)
    If (Int(Rnd * 2) = 0) Then Picture1.PSet (X&, Y&)
  Next X&
Next Y&

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
I always knew that the programmers at Microsoft must be bonkers, but at least they have taste.
[tongue]

Not bad Andy, not bad at all... [thumbsup]

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
Still up? Maybe I did something wrong. Nothing close to that comes out. I set up the form as you indicated and used this code since you didn't show how you declared Y& and X&.

Code:
Dim y As Long
Dim x As Long

' Set the Rnd() seed to Angelina Jolie's date of birth
Randomize DateSerial(1975, 6, 7)
For y = 0 To Picture1.ScaleHeight - 1
    For x = 0 To Picture1.ScaleWidth - 1
    ' Plot a point if the Rnd() function returns an even number.
    ' If you plot odd numbers the image will be negative (white on black)
    If (Int(Rnd * 2) = 0) Then Picture1.PSet (x, y)
    Next x
Next y

Did I miss something?

 
I did not think that was possible so I tested it, hoping to get the same results. At first it looked promising.
IMG


But after 30,000 more iterations I get this.
IMG

Maybe I am using the wrong seed.
 

MajP,

Looks like Angelina Jolie to me (35 years from now....) :)

Have fun.

---- Andy
 
Strange. I tested your code yesterday Andy and it produced exactly the same image that you posted. But when I ran it today all I got was a speckled image.
Then I realised why the results were different. Angelina is now a day older. [thumbsup2]

[gray]Experience is something you don't get until just after you need it.[/gray]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top