Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: Check randomly generated numbers have not been used before # Math!

by LanX (Saint)
on Jun 21, 2014 at 14:30 UTC ( [id://1090774]=note: print w/replies, xml ) Need Help??


in reply to Re: Check randomly generated numbers have not been used before
in thread Check randomly generated numbers have not been used before

> The odds of an actual collision for a 7-digit random number are so astronomically small that I quite frankly would not bother to check for it.

the odds for no collision are easily calculated:

> perl -e ' $x=1; $x*=(1e7-$_)/1e7 for 1..3723; print $x ' 0.499919268547978

So the odds of a collision is already bigger than 50% after 3723 draws!¹

Actually there are already combinatorial formulas that avoids the loop completely.

For the interested readers:

Cheers Rolf

(addicted to the Perl Programming Language)

¹) and bigger than 99% after 9600 draws!

²) which many of us should have encountered at school already ... :-/

  • Comment on Re^2: Check randomly generated numbers have not been used before # Math!
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1090774]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-04-18 13:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found