Search Results
Search type | Search syntax |
---|---|
Tags | [tag] |
Exact | "words here" |
Author |
user:1234 user:me (yours) |
Score |
score:3 (3+) score:0 (none) |
Answers |
answers:3 (3+) answers:0 (none) isaccepted:yes hasaccepted:no inquestion:1234 |
Views | views:250 |
Code | code:"if (foo != bar)" |
Sections |
title:apples body:"apples oranges" |
URL | url:"*.example.com" |
Saves | in:saves |
Status |
closed:yes duplicate:no migrated:no wiki:no |
Types |
is:question is:answer |
Exclude |
-[tag] -apples |
For more details on advanced search visit our help page |
This tag is for questions pertaining to random numbers, whether pseudo random or truly random.
11
votes
Accepted
Picking 10 distinct words 'randomly' from List of unique words
First off, don't make a new Random instance every iteration. … Imagine picking 1.000.000 words in random order from a list of 1.000.000, getting the last word is a 1 in a million chance to get right. …
5
votes
Read from a file and pick a random line
inputs.hasNext()) {
throw new EmptyInputException();
}
T currentPick = inputs.next();
long totalInputs = 1;
Random random = new Random();
while (inputs.hasNext()) { … (long totalInputs, Random random) {
return nextLong(random, totalInputs) == 0;
}
private static long nextLong(Random random, long bound) {
return (long) (random.nextDouble() * bound);
} …