0

Based on that answer I was wondering how to implement this.

The goal is to have unique numbers. They have to be unique in the process not outside of it. So the recommendation was just to count.

import sys
i = iter(range(sys.maxsize))

# calling this will give you the next number
next(i)

What do you think about this approach?

buhtz
  • 10,774
  • 18
  • 76
  • 149
  • 1
    why not uuid (mapped back to int)? – Learning is a mess Feb 16 '22 at 15:07
  • 1
    Btw, range is already a lazy iterator, you don't need to call `iter` on it. And what do you mean by outside of the process? – Learning is a mess Feb 16 '22 at 15:08
  • What is a lazy iterator? Any suggestions for alternatives? "outside" in the meaning of a uuid4 would be unique outside the process. – buhtz Feb 16 '22 at 15:44
  • Lazy iterator means that you are not storing all the values simultaneously, but a state (one integer) and the iteration (increment by 1). I still not sure what you mean by unique outside the process. Do you mean reproducible? Giving the same values across different runs – Learning is a mess Feb 16 '22 at 15:46
  • No not reproducable. LAzy is good I think. I do not want to store all values from 0 to maxsize at once. – buhtz Feb 16 '22 at 15:48

0 Answers0