I have 5 dice and I roll each of them once: say outcome is dice[] = { 1, 1, 1, 1, 1 }
this dice[] array is the input to a function say
int random (dice) {
//do some thing with the dice values { 1, 1, 1, 1, 1 } ( as input from user )
//return a uniform random number between 1 to 100
}
Rule: only source of randomness is the values in the dice array. How do I may each of the values to a number in 1 to 100 so that the resulting values are almost uniform generation
please help
You could multiply the numbers on the dice by 1, 6, 6^2, 6^3, 6^4 respectively. Then add them up and take the last two digits of the result (that is, do a % 100 at the end).
Edit (thanks pjs)
As a last step, add 1, so that you get an answer between 1 and 100, not between 0 and 99.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.