Something like that, yes. If that fits in your constraints.
Do you know, I think it just might! Gonna play.
Thanks, everyone.
Problem I see with that is it wouldn’t survive sessions, and if I need 10 digit numbers I would be generating them every time.
That said, I’m not ruling it out.
Cool. The index and seed could survive sessions if you keep track of them, but yes, the list would be constructed each time you want to retrieve a number.
Just spit-balling here.
That’s certainly a lot easier to understand!
If you need to produce ten trillion distinct numbers, you’d be wrangling a pretty big list, but for small N, I’d certainly go for it.
Warning: I got c
and seed
backwards. My fault for reading too fast.
Although now that I think of it, since the generator function creates and shuffles the list, this is not really any different from my initial solution way up above:
data=list(range(100))
- set the random seed
random.shuffle(data)
- select sequentially, keeping track of index across sessions
I guess it’s maths to the rescue after all…
@alcampopiano - one potential issue might be implementation?
If something changes “underneath” with the RNG for instance, the sequence might change. The pure maths method should remain constant.
I think?
@alcampopiano
the problem with your way is that I want a large spread of numbers, even if I’m only ever going to retrieve a small percentage of them over the course.
So I might need a range between roughly 1,000,000 and 9,999,999 even if I only ever use 50,000 of them. To do that with list shuffling takes both a long time (verified) and I imagine a lot of memory (not verified).
Ya, very true. I see what you mean.
Notwithstanding concerns about the RNG implementation, this is my last try, I swear.
random.sample(range(1000000, 10000000), 500001)[500000]
This selects the 500,000th element from a range of random non-duplicating integers, between 1M and 10M (population size is 500001).
It takes about .5 seconds on my computer.
Used in conjunction with setting the seed, you’d have a predictable and fairly memory-efficient way of getting the desired number (I think).
This was a wonderful distraction…
That looks more interesting
I shall play and report back (probably tomorrow now)