in reply to Check randomly generated numbers have not been used before
Replies are listed 'Best First'. | |
---|---|
Re^2: Check randomly generated numbers have not been used before
by BrowserUk (Patriarch) on Jun 20, 2014 at 19:28 UTC | |
If you had any programming skills, you'd make some attempt to verify a wild-assed guess like that:
Using one of the best PRNGs around, that hits a duplicate after less than 4000 attempts on average, and as few 500. Best you stick to your fluff pieces, handing out bad advice that could ruin young guys careers; at least then you cannot be proven wrong!. With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [d/l] |
Re^2: Check randomly generated numbers have not been used before # Math!
by LanX (Saint) on Jun 21, 2014 at 14:30 UTC | |
the odds for no collision are easily calculated:
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 ... :-/ | [reply] [d/l] |
Re^2: Check randomly generated numbers have not been used before
by marto (Cardinal) on Jun 21, 2014 at 13:45 UTC | |
As if the world needed any more reasons not to invest in your services. | [reply] |
Re^2: Check randomly generated numbers have not been used before
by Anonymous Monk on Jun 20, 2014 at 17:06 UTC | |
... I quite frankly would not bother to check for it. R3search3R said the check is to avoid duplicate part numbers, and didn't say how many numbers they're generating, so that advice seems very wrong. R3search3R: Why aren't you using a real database for this? Here's a solution based on your approach, but note that if the list is long and this is run often, it's horribly inefficient because it reads the entire file every time it's run.
Note that you'll probably want to change the values of $database and $part_number_range, and remove the statements marked with # DEBUG after testing. | [reply] [d/l] [select] |
Re^2: Check randomly generated numbers have not been used before
by jdporter (Paladin) on Jun 02, 2015 at 17:55 UTC | |
The probability of two truly random integers in that range being the same is exactly 1 in 10,000,000. Small, yes, but astronomically small? I wouldn't say so. Certainly not as "astronomical" as the odds of getting a Royal Fizzbin. | [reply] |
by marto (Cardinal) on Jun 03, 2015 at 10:19 UTC | |
Considering you posted this on a Tuesday, a Royal Fizzbin would have been quite the hand indeed! | [reply] |