dimanche 8 octobre 2017

Dynamically exclude some numbers from randomly generated sequence

I want to produce some random sequence of numbers between a range, for example 100 to 200.

After a while, depending on some events, I want to produce some new sequence between the same range (100 to 200), but this time I want to exclude some numbers.

for example I don't want [150,165,170].

for the next time, These excluded numbers may or may not be included in the sequence.

One possible approach could be an array of numbers like this:

int rndm[] {100,101,102,103,...};

and use the index of the array to generate a random number at a time:

random(rndm[0-99]); 

but I need to use as few instruction/data structures as possible in order to achieve performance.

I am using C for this code and I use random() or randomSeed(seed) and I want to know what is the most efficient approach to handle this issue in terms of data structures should be used for the speed and memory?

Aucun commentaire:

Enregistrer un commentaire