Linked Questions
17 questions linked to/from What is the optimal algorithm for generating an unbiased random integer within a range?
-2 votes
1 answer
951 views
C : How can I create random numbers certain range? [duplicate]
I want to create some specific random, such that from 10 to 20. rand()%20; is create from 0 to 19
191 votes
14 answers
345k views
How do you generate uniformly distributed random integers?
I need a function which would generate a random integer in a given range (including boundary values). I don't have unreasonable quality/randomness requirements; I have four requirements: I need it to ...
42 votes
4 answers
271k views
How do I generate a random number between two variables that I have stored? [duplicate]
Possible Duplicate: Generating random integer from a range I am trying to create a program where the computer guesses a number the user has in his/her mind. The only user input required is whether ...
16 votes
7 answers
19k views
Why is the use of rand() considered bad? [duplicate]
Usage of rand() is usually frowned upon despite using a seed via srand(). Why would that be the case? What better alternatives are available?
12 votes
4 answers
29k views
Generating a uniform distribution of INTEGERS in C
I've written a C function that I think selects integers from a uniform distribution with range [rangeLow, rangeHigh], inclusive. This isn't homework--I'm just using this in some embedded systems ...
20 votes
4 answers
9k views
Uniformity of random numbers taken modulo N
One common way of choosing a random number in [0, n) is to take the result of rand() modulo n: rand() % n. However, even if the results returned by the available rand() implementation are fully ...
16 votes
5 answers
2k views
How to generate a random integer in the range [0,n] from a stream of random bits without wasting bits?
I have a stream of (uniform) random bits from which I'd like to generate random integers uniformly in the range [0,n] without wasting bits. (I'm considering bits wasted which are in excess of floor(...
2 votes
2 answers
6k views
Guaranteeing three digits in a randomly generated number
I had an assignment that required us to generate a three digit number twice so a student can add them together and then check their work. I am still very, very new to C++ and my class regretfully ...
4 votes
2 answers
2k views
How to generate an un-biased random number within an arbitrary range using the fewest bits
Because of the pigeon hole principle, you can't just use output = min + (rand() % (int)(max - min + 1)) to generate an unbiased, uniform, result. This answer to a similar question provides one ...
1 vote
3 answers
3k views
Dice Roller for any sided dice in VB.Net
I am wanting to create a dice roller so that the user can choose a number of sides on a dice and it will randomise the response, My current code chucks out the same number all of the time. Sub ...
4 votes
2 answers
1k views
How to create a uniform distribution over non-power-of-2 elements from n bits?
Assuming I can generate random bytes of data, how can I use that to choose an element out of an array of n elements? If I have 256 elements I can generate 1 byte of entropy (8 bits), and then use ...
3 votes
1 answer
372 views
What is the most rng-efficient uniform random integer algorithm? [duplicate]
This is not a duplicate of #11766794 “What is the optimal algorithm for generating an unbiased random integer within a range?”. Both its top-upvoted answer and its Accepted answer have to do with ...
0 votes
2 answers
422 views
Data from table into C++ quiz application
I wrote a code which shows a question and 4 answers, ask to choose the correct one, and checks the choice. Now I would build a table which would contain 6 columns: question/a/b/c/d/correct_answer, and ...
2 votes
2 answers
162 views
Math.NET CryptoRandomSource Next is Biased
I am developing a gaming platform that is subject to heavy regulatory scrutiny. I chose Math.NET because it seemed like a good fit. However I have just received this comment back from our auditors. ...
-2 votes
2 answers
92 views
Random integral numbers from uniform distribution
I have to write a c++ program and have a problem only with the following part: [...] for that purpose, you will need two random integral numbers from uniform distribution on the set {0,1,...,9} (...