Avoid using the obsolete rand module; and improve the randomness
of the boundary chosen by choose_boudary() by using milliseconds of the timestamp.
This commit is contained in:
parent
5fb2b61c64
commit
5c7e8cd267
|
@ -109,7 +109,7 @@ _prefix = None
|
||||||
def choose_boundary():
|
def choose_boundary():
|
||||||
global _prefix
|
global _prefix
|
||||||
import time
|
import time
|
||||||
import rand
|
import whrandom
|
||||||
if _prefix == None:
|
if _prefix == None:
|
||||||
import socket
|
import socket
|
||||||
import os
|
import os
|
||||||
|
@ -122,10 +122,9 @@ def choose_boundary():
|
||||||
pid = `os.getpid()`
|
pid = `os.getpid()`
|
||||||
except:
|
except:
|
||||||
pid = '1'
|
pid = '1'
|
||||||
seed = `rand.rand()`
|
|
||||||
_prefix = hostid + '.' + uid + '.' + pid
|
_prefix = hostid + '.' + uid + '.' + pid
|
||||||
timestamp = `int(time.time())`
|
timestamp = '%.3f' % time.time()
|
||||||
seed = `rand.rand()`
|
seed = `whrandom.randint(0, 32767)`
|
||||||
return _prefix + '.' + timestamp + '.' + seed
|
return _prefix + '.' + timestamp + '.' + seed
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue