On Tue, 26 Jul 2022 23:47:59 +0200, Cecil Westerhof <ce...@decebal.nl> declaimed the following:
>The new code: > from random import SystemRandom > system_random = SystemRandom() > index = system_random.randint(0, len(to_try) - 1) > >The first two statements are executed once. >The last statement I think about 75 * 10 ** 6. > >So it seems that my first idea of using randbelow was the correct one. >But if anyone could explain why SystemRandom is so much more >expensive, I would be interested to know it. >(Or am I still doing something wrong?) What happens with system_randint = SystemRandom().randint #no parens index = system_randint(...) which may remove the method lookup from the repetition. -- Wulfraed Dennis Lee Bieber AF6VN wlfr...@ix.netcom.com http://wlfraed.microdiversity.freeddns.org/ -- https://mail.python.org/mailman/listinfo/python-list