943,971 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 6995
  • Java RSS
Oct 6th, 2004
0

Random numbers...really random??

Expand Post »
I made a program that simulates the roll of a six sided dice. I had my program return a random number between 1 and 6. The weird thing is I get 4 like 6 out of 10 times each time I run the program. So is the random number genarator really random or is there a way to make numbers more random?
Similar Threads
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Oct 6th, 2004
0

Re: Random numbers...really random??

>So is the random number genarator really random
No. The random number generator creates pseudorandom numbers that just look good to a point. Depending on the quality of the generator that point will be quick to arive or not.

>The weird thing is I get 4 like 6 out of 10 times each time I run the program.
That sounds fairly normal. A completely random distribution would have each number equally likely to come up. But pseudorandom numbers aren't quite that good and you can expect slightly skewed results. The best solution is to provide as random of a seed as you can, or replace the random number generator with something better.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Oct 6th, 2004
0

Re: Random numbers...really random??

Most of the computerized random number generators that I have seen use the last few digits of the time field (milliseconds?) as the seed. Since the start time is going to be random this starts of the random number generator at a random spot in its sequence.

Computer random number generators usually use a formula to derive one number from the previous and eventually cycle through all possible numbers between zero and a fairly large number (usually tens of thousands) but jumping all over the place within the number range during the process. As you usually only want a small number (say up to 100) returned when these tens of thousands of numbers are scaled down they give the appearance of a random sequence of numbers.

The important thing to remember with random number generators is that if you start with the same seed then you will always get the same "random" sequence. That is why you need to use a random number to seed the generator to start with.
Reputation Points: 13
Solved Threads: 1
Junior Poster in Training
felgall is offline Offline
50 posts
since Aug 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Need Help with variable initialization
Next Thread in Java Forum Timeline: help with polymorphism and inheritance...getting null values





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC