View Single Post
tomoe
Veteran Member
 
Join Date: Nov 2006
 
2009-10-06, 11:28

Quote:
Originally Posted by ShadowOfGed View Post
Wait, nobody's going to suggest the generic solution?
  • Concatenate inputs into a list of numbers
  • Calculate sum of all values
  • Obtain random value (rand * sum)
  • Find greatest i where sum(list[0..i]) < value
  • Return i (your index)

That would work for more than 3! And in some ways, may better represent what's happening. Not saying it's *faster* at all.
That's exactly what I do when programming grid worlds. Much simpler and more general.
  quote