本文整理汇总了Python中urandom.getrandbits方法的典型用法代码示例。如果您正苦于以下问题:Python urandom.getrandbits方法的具体用法?Python urandom.getrandbits怎么用?Python urandom.getrandbits使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类urandom
的用法示例。
在下文中一共展示了urandom.getrandbits方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ptr_test
# 需要导入模块: import urandom [as 别名]
# 或者: from urandom import getrandbits [as 别名]
def ptr_test(dial):
ptr = Pointer(dial)
v = 0j
steps = 20 # No. of interpolation steps
grv = lambda : urandom.getrandbits(16) / 2**15 - 1 # Random: range -1.0 to +1.0
while True:
v1 = grv() + 1j * grv() # Random vector
dv = (v1 - v) / steps # Interpolation vector
for _ in range(steps):
v += dv
mag = abs(v)
if mag < 0.3:
ptr.value(v, BLUE)
elif mag < 0.7:
ptr.value(v, GREEN)
else:
ptr.value(v, RED)
await asyncio.sleep_ms(200)
# Analog clock demo. Note this could also be achieved using the Dial class.
示例2: writer
# 需要导入模块: import urandom [as 别名]
# 或者: from urandom import getrandbits [as 别名]
def writer(self):
self.verbose and print('Started writer')
while True:
gc.collect()
data = [self.tx_msg_id, self.cl.connects, gc.mem_free(),
self.cm.dupe, self.cm.miss]
self.tx_msg_id += 1
print('Sent', data, 'to server app\n')
dstr = ujson.dumps(data)
await self.cl.write(dstr) # Wait out any outage
await asyncio.sleep_ms(7000 + urandom.getrandbits(10))
示例3: random_wink
# 需要导入模块: import urandom [as 别名]
# 或者: from urandom import getrandbits [as 别名]
def random_wink(id=None):
if not eyes.animation_is_playing():
eye_nr = urandom.getrandbits(1) + 1
col_sel = wink_colors[urandom.getrandbits(2)]
eyes.animation("s 1 black s 2 black f {} {} p 1000 f 1 black f 2 black p 1000".format(eye_nr, col_sel))
schedule_next_wink()
示例4: schedule_next_wink
# 需要导入模块: import urandom [as 别名]
# 或者: from urandom import getrandbits [as 别名]
def schedule_next_wink():
# time_delta = 100+urandom.getrandbits(7)
time_delta = 45 + urandom.getrandbits(6)
do_later(time_delta, random_wink)
示例5: random_from_crypto
# 需要导入模块: import urandom [as 别名]
# 或者: from urandom import getrandbits [as 别名]
def random_from_crypto():
""" """
platform_info = get_platform_info()
if platform_info.vendor == platform_info.MICROPYTHON.Pycom:
# https://forum.pycom.io/topic/1378/solved-how-to-get-random-number-in-a-range/6
# https://github.com/micropython/micropython-lib/blob/master/random/random.py
import crypto
r = crypto.getrandbits(32)
else:
import urandom
r = urandom.getrandbits(32)
return ((r[0] << 24) + (r[1] << 16) + (r[2] << 8) + r[3]) / 4294967295.0