How to get random number with each number has its own probability [duplicate]
问题 This question already has answers here : how to implement non uniform probability distribution? (3 answers) Closed 6 years ago . For example, I want to get random number from set S = {0, 1, 2, 3}. But instead of each number has same probability to shown (which is 25%), now I have different probability for each number, let say {50%, 30%, 20%, 10%}. How do I code this? In Java or C# (I prefer C#). 回答1: The Alias Method is by far my favorite for doing this. http://code.activestate.com/recipes