float p = (rand() / static_cast<float>(RAND_MAX)) * total_probability;
s* current = &sArray[0];
while ( (p -= current->probability) > 0)
++current;
// `current` now points to your chosen target
More Related Contents:
- Why do people say there is modulo bias when using a random number generator?
- How to generate a random number in C++?
- Generate random numbers using C++11 random library
- Why does rand() yield the same sequence of numbers on every run?
- How to generate different random numbers in a loop in C++?
- Create Random Number Sequence with No Repeats
- Random number generation in C++11: how to generate, how does it work? [closed]
- How to succinctly, portably, and thoroughly seed the mt19937 PRNG?
- Generate random numbers following a normal distribution in C/C++
- Rand() % 14 only generates the values 6 or 13
- Same random numbers every loop iteration
- generate random double numbers in c++
- Random array generation with no duplicates
- How does modulus and rand() work?
- Need for predictable random generator
- Random number c++ in some range [duplicate]
- What is the optimal algorithm for generating an unbiased random integer within a range?
- How do I generate thread-safe uniform random numbers?
- Random number generator that produces a power-law distribution?
- How to generate random variable names in C++ using macros?
- Getting big random numbers in C/C++
- Generating a random integer from a range
- Random output different between implementations
- Is 1.0 a valid output from std::generate_canonical?
- Same random numbers every time I run the program
- What is a seed in terms of generating a random number? [duplicate]
- The implementation of random_device in VS2010?
- stl random distributions and portability
- How does calling srand more than once affect the quality of randomness?
- What difference between rand() and random() functions?