[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: generating unique random numbers
a kusa schrieb am 22.02.2010 um 11:14:11 (-0600): > What I did was to call math:random() twice and adding the results each > time around. I don't think addition significantly lowers the likelihood of getting two equal numbers. Imagine rolling dice, there is a chance of 1:6 of getting two equal numbers. Now take two dice, and try to match the sum of the first round in the second round: the probability will depend on the result of the first round and will be bell-curved, meaning higher probability for values in the middle and a value-space from 2 to 12. Now imagine multiplying the results: The value-space becomes largesr, sparser, and hence less prone to duplicates. Do the Perl: perl -lwe 'for $x(1..6) {for $y(1..6){print$x+$y}}' | sort -n | uniq -c 1 2 2 3 3 4 4 5 5 6 6 7 5 8 4 9 3 10 2 11 1 12 perl -lwe 'for $x(1..6) {for $y(1..6){print$x*$y}}' | sort -n | uniq -c 1 1 2 2 2 3 3 4 2 5 4 6 2 8 1 9 2 10 4 12 2 15 1 16 2 18 2 20 2 24 1 25 2 30 1 36 That's not a proof, of course, it's just the helpless expression of what I think is the case here. More knowledgeable mathematical assessments appreciated! > And I used distinct-values() everytime. How do you use it? -- Michael Ludwig
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|