I have to generate a random number from a range with exceptions held in a bool array, is there a way to do it without a loop depending on probability? There is also a potential infinite loop here if all values are false. Any suggestions?
bool[] paths = InnateChannels(channelID, channelOrientation);
bool done = false;
int iDirection = 0;
while (!done)
{
iDirection = Random.Range(0, 4);
if (paths[iDirection])
done = true;
}
direction = DirectionToVector(iDirection);
paths
array contains these values:{ true, true, false, true, false, false, true }
- how many random number do expect from it? Currently it's a totaly random result but apperently you don't want it like that so what would be the correct result? \$\endgroup\$