Python Forum
RNG; One variable must not be equal to another
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
RNG; One variable must not be equal to another
#7
(Oct-09-2018, 10:31 PM)micseydel Wrote: Using combinations() here is clever but wouldn't scale. What you want is "sampling without replacement" and the easiest way to do that would be with a numpy function which allows you to set replacement to False. Apparently Python's random module doesn't have this built-in, which is somewhat unfortunate.

If you don't mind adding a dependency, I'd use numpy. Otherwise the random number generation and set checking is probably what I would do. As a third option, you could consider using the built-in random.shuffle() one time and then popping (this would be less efficient than set-checking, but more efficient than combinations).

I am starting to think last night that the thing I want to happen is beyond me for now, and I am starting to give up. But thanks for suggesting me three options, I'll look to them.
Reply


Messages In This Thread
RE: RNG; One variable must not be equal to another - by DavidRobinsons - Oct-10-2018, 12:39 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020