From 6076e1832a66b04a3d4d1d7d7dc53be7252da9c3 Mon Sep 17 00:00:00 2001 From: Mahendra Date: Wed, 21 Mar 2018 18:19:08 +0530 Subject: [PATCH] implement more helper random changes with replace random.xxx --- src/helper_random.py | 11 ++++++++--- src/multiqueue.py | 3 ++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/helper_random.py b/src/helper_random.py index df2eec49..c11ef695 100644 --- a/src/helper_random.py +++ b/src/helper_random.py @@ -1,9 +1,11 @@ import os import random from pyelliptic.openssl import OpenSSL +NoneType = type(None) + def randomBytes(n): - """Method randomBytes.""" + """Method randomBytes.""" try: return os.urandom(n) except NotImplementedError: @@ -30,7 +32,7 @@ def randomsample(population, k): return random.sample(population, k) -def randomrandrange(x, y): +def randomrandrange(x, y=None): """Method randomRandrange. return a randomly selected element from @@ -38,4 +40,7 @@ def randomrandrange(x, y): choice(range(start, stop)), but doesnt actually build a range object. """ - return random.randrange(x, y) + if isinstance(y, NoneType): + return random.randrange(x) + else: + return random.randrange(x, y) diff --git a/src/multiqueue.py b/src/multiqueue.py index 62b0fa87..be5ce44f 100644 --- a/src/multiqueue.py +++ b/src/multiqueue.py @@ -1,6 +1,7 @@ from collections import deque import Queue import random +import helper_random class MultiQueue(Queue.Queue): defaultQueueCount = 10 @@ -24,7 +25,7 @@ class MultiQueue(Queue.Queue): # Put a new item in the queue def _put(self, item): #self.queue.append(item) - self.queues[random.randrange(self.queueCount)].append((item)) + self.queues[helper_random.randomrandrange(self.queueCount)].append((item)) # Get an item from the queue def _get(self):