Advertisement

Latest probabilities Activity

Is this algorithm (probabilities calculations) going to perform bad for my game?

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…
6,959 views
Advertisement

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…
7,704 views
Advertisement
Advertisement