|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Random Number Question
ok do you have a better chance of getting a repeat if you have an 8 digit random number or 2 concatinated 4 digit numbers? or 4 concatinated 2 digit numbers?
__________________
My brain cells are like a storm trooper's armor: useless |
|
#2
|
|||
|
|||
|
humn
interesting question!
which algo r u using ? i think it wud work better keeping it simple and choosing a better algorithm if u r dead into doin concatenation then the results depend on the algorithm but shud not be of much siginificance in improvement thats wats my opinion! will check it n let ya know! till then keeping experimenting111111 |
|
#3
|
|||
|
|||
|
It's a matter of statistics.
Probability = favorable cases / possible cases For eight digits, the chance is P = 1 / 10^(8-1) For 4 and 2 digits, you have to chain the events. For example, when u have 2 groups of 4 digits, not only the first group has to be a repeat, but also the 2nd one in order to be a full repeat. Hope that helps. |
|
#4
|
||||
|
||||
|
Hehe just saw this question. Assuming we have a good random number generator and assuming the restriction that the random number has to always be 8 digits long, we get some very interesting conclusions:
To make a random 8 digit number from four 2 digit numbers, we must ensure that each of the four numbers picked is 2 digits long (we're assuming no left padding a number with zeroes, if the number is only one digit long). For each two digit number, there are (99 - 10 + 1) possible combinations (i.e) max 2 digit number - min 2 digit number + 1 = 90 possible combinations. Hence, to make an 8 digit number from four two digit picks, we get 90 * 90 * 90 * 90 = 65,610,000 possibilities. For a random 4 digit number under the same conditions, there are 9999 - 1000 + 1 = 9000 possibilities. Hence, concatenating two 4 digit numbers gives us 9000 * 9000 = 81,000,000 possibilities. For a random 8 digit number, there are (99,999,999 - 10,000,000 + 1) = 90,000,000 possibilities. Therefore, with our restrictions noted above, picking four 2 digit numbers gives us the best chance of repeating a number. Note that if you remove the restriction for numbers to always be eight digits long and/or remove the rule about not left padding single digit numbers with 0's, then there will be equal probabilities, i.e 1 in 10^8.
__________________
Up the Irons What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home. "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest Down with Sharon Osbourne Puzzle of the Month solved by Keath and KevinADC, superior perl programmers of the month |
|
#5
|
|||
|
|||
|
No difference if ...
Why shouldn't 4 or 2 digit numbers start with a 0? If they do, i.e. if you generate numbers between 0 and 9999 or 0 and 99, all probabilities are identical.
If you are interested in increasing the number of repetitions, you should follow another strategy. The one suggested by the previous replier is to leave out digits (in his case, the digit 0 at the start of a number). E.g., if you only allow 1s in your "random" numbers, the number of repeats is quite high. You could also write a biased generator that generates digit for digit and for every next digit first tests if it should be repetition of the previous one, and otherwise choose from the remaining 9. |
|
#6
|
|||
|
|||
|
interesting question.
I assume we're really trying to minimize repeats. Given that a RNG is designed to achieve a uniform distribution across its output window, I tend to think that it's easier to heuristically design a RNG algorithm that approaches the uniform distribution across the integers 0-9 rather than over a larger set, since there will be less potential holes. If this is true, then a concatenation of 8 single-digit RN's would be more random (closer to a uniform distribution over the long haul) than an 8-digit RN. Just a thought..
__________________
Last edited by CokeJunkie : September 29th, 2003 at 06:23 PM. |
|
#7
|
|||
|
|||
|
It ain't that bad...
There are good RNGs that can generate true 32 bit random values, so that would be sufficient to generate 8 digits. If you have a bad RNG, you wouldn't want to have it generate 8 digits in a row, since they are known to have rather strong relations between successive draws (e.g., the linear congruency method used in all standard C libraries for rand() always switches between odd and even on successive draws...).
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Software Design > Random Number Question |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|