Something like this:
void exRand(minvalue, maxvalue, exclude, excludeRange, excludeList)
exclude sets a specific number to exclude.excludeRange sets a range of numbers to exclude
excludeList reads numbers from a list, and excludes those
If exRand produces a number from any of these excluded values, it clears that value, and produces another random value, repeating this, until it produces one that is not excluded.
I should probably add that function to something, as it shouldn't be hard to create, although the excludeList would be a tad tricky to work out in a way that isn't hideous.
This is a pretty inefficient implementation of this idea. In general, you should only need a rand() function that gives values between 0 and 1. With that, you can do:
minvalue + rand()*(maxvalue-minvalue)
which gives a range between minvalue and maxvalue, (rounding to int if necessary.) In fact, I wouldn't be surprised if this is how the function is defined. or
exclusionmap( minvalue + rand()*(maxvalue-minvalue-sum(excludelist)) )
where exclusion map adds to a value and offset given by the sum of values on the list that occur before the block that the value lands in. In fact, with this method you can treat zero-minvalue as just part of the excludelist.
If you are re-rolling rand(), you never actually know how long your function will run.
Edited by RetraRoyale, 22 April 2014 - 03:24 PM.