Pinal Dave will teach you tricks to help identify the real root cause of database problems rather than red herrings. Attendees will learn scripts that they can use in their environment to immediately figure out their performance Blame Shifters and fix them quickly.

Yes it will work:

If you want random numbers from 1 to 5 and have a normal die, you may throw it and whenever a 6 come up, just disregard it and throw again. The fact that your process allows a number out of the range you are looking for (like 6) to come up from time to time does not influence in any way whatsoever the probability of any of the numbers you are looking for to be selected as the answer. ie, the fact that the die has six sides does not make the chance to get a "2" larger than the chance to get a "4". IT would be completely wrong to try and map the 6 to some number in the range!

Now, just use a bigger die, and disregard more of its "unwanted" sides. By selecting R1 randomly from randomly from 0 - 2486 and R2 randomly from 0 - 999, the following formula:

RESULT = (R1 * 1000) + R2

will give you RANDOM numbers 0 - 2486999 with equal probability.

R1 = 0 and R2 = 0 will yield RES = 0 (our minimum value)

and R1 = 2486 and R2 = 999 will yield 2486999 (our maximum value)

since we are looking for numbers 1 to 2486813, just disregard the complete try when RESULT == 0 or RESULT > 2486813

Please note my second post on the 371 and 6703 solution (the first one was done in a hurry and I made a mistake):

the solution is:

r1 = random number from 1 to 371

r2 = random number from 1 to 6703

result = (r1 - 1) * 6703 + r2

ie, for minimum result = (1-1)*6703+1 = 1

maximum result = (371-1)*6703+6703 = 2486813

All the numbers have exactly the same chance of being selected:

we divide our numbers into 371 dice, each with 6703 sides

we then select one die from the 371 dice (you agree everybody still have an equal chance)

now we roll our die and whichever number is facing up (on our 6703 side die) is our winner.

for 1-21 you would take r1 from 1-3 and r2 from 1-7 then

result = (r1-1)*7 + r2

for 0-21 (this means 22 possibilities) you could use 1-2 and 1-11

with result = (r1-1) * 11 + r2 - 1

or you may take 4 dice (normal 6 sided) and go the "disregard" route.

label the first die's sides 0-5

the next 6-11

then 12-17

and the last 18,19,20,21,X,X

pick one of the four randomly and throw it

if an "X" pops up, START again

whew...