View Single Post
Dave
Ninja Editor
 
Join Date: May 2004
Location: Bay Area, CA
 
2009-10-04, 14:02

In C, not Java, and assuming A, B, and C are ints...
Code:
int foo(int a, int b, int c) { float total = a + b + c; float aThreshold = a / total; float bThreshold = aThreshold + (b / total); float n = rand() / RAND_MAX; //don't know what this constant is called in Java if(n <= aThreshold) return a; if(n <= bThreshold) return b; return c; }
Test it to make sure the algorithm is correct before using it. I'm tired and not thinking straight.
  quote