Hi collective unconscious,
Suppose that you have a range of numbers from 0 to N that you want to randomly separate in groups of max M sequential numbers. This is easily done with a bitmap and a random number generator, but it is not space efficient for very large instances of N.
So, what I want is a generator that, given a number N and M, will start producing non-overlapping groups in a random order and with random size, with less than O(n) space efficiency.
E.g. for N = 7 and M = 3, a valid output is the following:
4
1, 2
3
5, 6, 7
0
Does anyone know an algorithm that can help in producing such an output?
Aucun commentaire:
Enregistrer un commentaire