mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Use system random source for picking a random book
This commit is contained in:
parent
359116e86a
commit
4c0138e40d
@ -21,6 +21,10 @@ class PickRandomAction(InterfaceAction):
|
|||||||
def genesis(self):
|
def genesis(self):
|
||||||
self.qaction.triggered.connect(self.pick_random)
|
self.qaction.triggered.connect(self.pick_random)
|
||||||
self.recently_picked = {}
|
self.recently_picked = {}
|
||||||
|
try:
|
||||||
|
self.randint = random.SystemRandom().randint
|
||||||
|
except Exception:
|
||||||
|
self.randint = random.randint
|
||||||
|
|
||||||
def location_selected(self, loc):
|
def location_selected(self, loc):
|
||||||
enabled = loc == 'library'
|
enabled = loc == 'library'
|
||||||
@ -38,7 +42,7 @@ class PickRandomAction(InterfaceAction):
|
|||||||
n = next(iter(rp))
|
n = next(iter(rp))
|
||||||
del rp[n]
|
del rp[n]
|
||||||
while True:
|
while True:
|
||||||
pick = random.randint(0, count)
|
pick = self.randint(0, count)
|
||||||
if pick in rp:
|
if pick in rp:
|
||||||
continue
|
continue
|
||||||
rp[pick] = True
|
rp[pick] = True
|
||||||
|
Loading…
x
Reference in New Issue
Block a user