0

My program frequently access random numbers. I initiate my random number generator via:

import random
random.seed(1) 

I'm calling random.uniform() a lot in code for an evoluationary model (biology) and it repeatidly hangs (doing nothing for 20 minutes and then I stop it) after a while. While it hangs Python is using my CPU with 20%-30% (I have four cores). At the same time it's using 10GB Ram (I am having a lot of data).

Can I do something to make the default random library not hang or is there another random libary I can use?

I'm running Spyder 4.2.5 with Python 3.8 on Windows 10. (The problem already existed with an earlier version of Spyder and I installed Spyder 4.2.5 from skretch)

ti7
  • 16,375
  • 6
  • 40
  • 68
Christian
  • 25,249
  • 40
  • 134
  • 225
  • are you using random from a thread? does it behave this way if you disable the pagefile? heavy-handed, but does using a more science-oriented operating system help? – ti7 Jun 12 '21 at 14:34

1 Answers1

1

Just speculating, but the default random module definitely shouldn't do that, so I suspect either

Try calling os.random with and without the blocking flag

import os
os.getrandom(1024, flags=os.GRND_NONBLOCK)  # raise for low entropy
ti7
  • 16,375
  • 6
  • 40
  • 68