🎉 Celebrating 25 Years of GameDev.net! 🎉
Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!
Latest probabilities Activity
The proposal by fastcall22 is the usual solution where you get an answer with one draw, and one walk over the original list until you find the item that you should get. It's a few lines of code:
float sum = 0;
foreach (KeyValuePair<string, float> pair in probabilities) sum += pair.Value;
floa…
In this particular case, to randomly select 5 elements from your list of names you could use:
Random rng = new Random();
for(int i=0; i<5; i++) {
//generates a random integer in [i,names.length)
int swapTarget = i + rng.nextInt(names.length - i);
String temp = names[i];
names[i] = names[swapT…
Advertisement
Advertisement