Given an array like [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], I want to get a random value that takes into consideration the position.
I want the likelihood of 1 popping up to be way bigger than 10.
Is something like this possible?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
For the sake of simplicity let’s assume an array
arr = [x, y, z]from which we will be sampling values. We’d like to see following relative frequencies ofx,yandz:Preprocess these frequencies to calculate margins for our subsequent dice roll:
Let’s sum them up.
Now choose a random number
Return
arr[index]as a result. To sum up:Let’s see how it works.
A histogram for
datashows thatsampleworks as we’ve intended.