"option b is impossible, unless the number of runs is a multiple of 10" - then it's not really impossible, is it? :laugh: @fzml Option A: Ok, for Option A, Luc's solution is what I'd go with (in fact I can't think of another way off the top of my head, at least one that's not contrived). Assume we have two sets of numbers, A and B. We want 30% chance of selecting something from A, and 70% chance of selecting something from B: in pseudo-C#, something like:
Random rnd = new Random();
int selector = rnd.Next(1, 10);
if (selector <= 3) { // select something from the A group }
else { // select something from the B group }
As you can see, the rnd.Next has 10 possible outputs (1, 2, 3 ... 10) - we assign 30% of those, i.e. 1 through 3, to our 30% group. The rest make up the 70% for the other group. If we wanted 3 groups with (A: 20%, B: 50%, C: 30%):
Random rnd = new Random();
int selector = rnd.Next(1, 10);
if (selector in {1, 2}) { // select something from the A group }
else if (selector in {3, 4, 5, 6, 7}) { // select something from the B group
else { // select something from the C group }
By splitting a known number of outcomes up like this, you can have "pre-determined probabilities". Of course, this all relies on the soundness of the Random generator you're using. If you would like to write your own, there's heaps of literature out there on the web about RNGs (check out the Mersenne Twister). Option B: Well, Option B (forgive me if I get the wrong terminology here) is about creating a pseudo-random number generator, with period of x, that selects members randomly from different sets based on enforced probabilities. Ok, well let's say you have two sets A and B:
A = { 1, 2, 3, 4 } // we want EXACTLY 30% of our answers to come from here
B = { 5, 6, 7, 8 } // we want EXACTLY 70% of our answers to come from here
You need to set a "period", that is, what number of interations will satisfy the exactness of our probabilities (for example, up until now we have assumed 100 iterations will satisfay the probabilities). So, let's say we pick 100 - that means every 100 iterations, we can look at our results and say for sure that 30% of these will be from A and the rest from B. A very simple way, based on Option A, would be (pseudo-code):