Merge pull request #128 from pacohope/use-system-random
Use underlying system random instead of homebrew randomsammachin-gprs
commit
b44cc3596b
|
@ -3,7 +3,7 @@
|
||||||
___name___ = "3D Spin"
|
___name___ = "3D Spin"
|
||||||
___license___ = "MIT"
|
___license___ = "MIT"
|
||||||
___categories___ = ["Demo"]
|
___categories___ = ["Demo"]
|
||||||
___dependencies___ = ["app", "ugfx_helper", "random", "sleep", "buttons"]
|
___dependencies___ = ["app", "ugfx_helper", "sleep", "buttons"]
|
||||||
|
|
||||||
import ugfx
|
import ugfx
|
||||||
from tilda import Buttons
|
from tilda import Buttons
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
___name___ = "Breakout"
|
___name___ = "Breakout"
|
||||||
___license___ = "MIT"
|
___license___ = "MIT"
|
||||||
___categories___ = ["Games"]
|
___categories___ = ["Games"]
|
||||||
___dependencies___ = ["app", "ugfx_helper", "random", "buttons"]
|
___dependencies___ = ["app", "ugfx_helper", "buttons"]
|
||||||
|
|
||||||
from tilda import Buttons
|
from tilda import Buttons
|
||||||
import ugfx, ugfx_helper, dialogs
|
import ugfx, ugfx_helper, dialogs
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
___name___ = "Conway game of life"
|
___name___ = "Conway game of life"
|
||||||
___license___ = "MIT"
|
___license___ = "MIT"
|
||||||
___categories___ = ["Games"]
|
___categories___ = ["Games"]
|
||||||
___dependencies___ = ["app", "ugfx_helper", "random", "sleep", "buttons"]
|
___dependencies___ = ["app", "ugfx_helper", "sleep", "buttons"]
|
||||||
|
|
||||||
import app, ugfx, ugfx_helper, buttons, sleep, time, random
|
import app, ugfx, ugfx_helper, buttons, sleep, time, random
|
||||||
from tilda import Buttons
|
from tilda import Buttons
|
||||||
|
|
|
@ -17,7 +17,7 @@ They also *may*:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
___license___ = "MIT"
|
___license___ = "MIT"
|
||||||
___dependencies___ = ["database", "buttons", "random", "app", "sleep", "ugfx_helper", "wifi", "sim800"]
|
___dependencies___ = ["database", "buttons", "app", "sleep", "ugfx_helper", "wifi", "sim800"]
|
||||||
|
|
||||||
import database, ugfx, random, buttons, tilda, sleep, ugfx_helper, wifi, time, sim800
|
import database, ugfx, random, buttons, tilda, sleep, ugfx_helper, wifi, time, sim800
|
||||||
from app import App
|
from app import App
|
||||||
|
|
|
@ -1,41 +0,0 @@
|
||||||
"""Library to generate random numbers
|
|
||||||
|
|
||||||
Warning! Don't use this for anything important, it's probably biased
|
|
||||||
"""
|
|
||||||
|
|
||||||
___license___ = "MIT"
|
|
||||||
|
|
||||||
# todo: simplify this by using "urandom"
|
|
||||||
import os
|
|
||||||
|
|
||||||
_bigrand_bytes = 10
|
|
||||||
_bigrand_max = pow(256, _bigrand_bytes)
|
|
||||||
|
|
||||||
def _bigrand():
|
|
||||||
"""generates a random number between 0 (incl) and _bigrand_max (excl)"""
|
|
||||||
base = 0
|
|
||||||
for b in os.urandom(_bigrand_bytes):
|
|
||||||
base = (base << 8) + b
|
|
||||||
return base
|
|
||||||
|
|
||||||
def random():
|
|
||||||
"""Return the next random floating point number in the range [0.0, 1.0)."""
|
|
||||||
return _bigrand() / _bigrand_max
|
|
||||||
|
|
||||||
def randrange(start, stop=None):
|
|
||||||
"""Return a randomly selected element from range(start, stop)"""
|
|
||||||
if stop is None:
|
|
||||||
stop = start
|
|
||||||
start = 0
|
|
||||||
return start + (_bigrand() * (stop - start) // _bigrand_max)
|
|
||||||
|
|
||||||
def randint(start, stop):
|
|
||||||
"""Return a random integer N such that a <= N <= b."""
|
|
||||||
return randrange(start, stop + 1)
|
|
||||||
|
|
||||||
def shuffle(seq):
|
|
||||||
"""Shuffle the sequence x in place."""
|
|
||||||
l = len(seq)
|
|
||||||
for i in range(l):
|
|
||||||
j = randrange(l)
|
|
||||||
seq[i], seq[j] = seq[j], seq[i]
|
|
|
@ -1,7 +1,7 @@
|
||||||
"""Tests for random lib"""
|
"""Tests for random lib"""
|
||||||
|
|
||||||
___license___ = "MIT"
|
___license___ = "MIT"
|
||||||
___dependencies___ = ["upip:unittest", "random"]
|
___dependencies___ = ["upip:unittest"]
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
from random import *
|
from random import *
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
"""
|
"""
|
||||||
___name___ = "Screen Party"
|
___name___ = "Screen Party"
|
||||||
___license___ = "MIT"
|
___license___ = "MIT"
|
||||||
___dependencies___ = ["ugfx_helper", "sleep", "random"]
|
___dependencies___ = ["ugfx_helper", "sleep"]
|
||||||
___categories___ = ["Homescreens"]
|
___categories___ = ["Homescreens"]
|
||||||
___bootstrapped___ = False
|
___bootstrapped___ = False
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,9 @@
|
||||||
___name___ = "Snake"
|
___name___ = "Snake"
|
||||||
___license___ = "MIT"
|
___license___ = "MIT"
|
||||||
___categories___ = ["Games"]
|
___categories___ = ["Games"]
|
||||||
___dependencies___ = ["dialogs", "app", "ugfx_helper", "random", "sleep", "buttons"]
|
___dependencies___ = ["dialogs", "app", "ugfx_helper", "sleep", "buttons"]
|
||||||
|
|
||||||
import math, ugfx, ugfx_helper, random, sleep, buttons
|
import app, math, ugfx, ugfx_helper, random, sleep, buttons
|
||||||
from tilda import Buttons
|
from tilda import Buttons
|
||||||
|
|
||||||
ugfx_helper.init()
|
ugfx_helper.init()
|
||||||
|
|
Loading…
Reference in New Issue