Merge pull request #128 from pacohope/use-system-random

Use underlying system random instead of homebrew random
sammachin-gprs
Bob Clough 2018-09-06 18:06:18 +01:00 committed by GitHub
commit b44cc3596b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 8 additions and 49 deletions

View File

@ -3,7 +3,7 @@
___name___ = "3D Spin"
___license___ = "MIT"
___categories___ = ["Demo"]
___dependencies___ = ["app", "ugfx_helper", "random", "sleep", "buttons"]
___dependencies___ = ["app", "ugfx_helper", "sleep", "buttons"]
import ugfx
from tilda import Buttons

View File

@ -3,7 +3,7 @@
___name___ = "Breakout"
___license___ = "MIT"
___categories___ = ["Games"]
___dependencies___ = ["app", "ugfx_helper", "random", "buttons"]
___dependencies___ = ["app", "ugfx_helper", "buttons"]
from tilda import Buttons
import ugfx, ugfx_helper, dialogs

View File

@ -3,7 +3,7 @@
___name___ = "Conway game of life"
___license___ = "MIT"
___categories___ = ["Games"]
___dependencies___ = ["app", "ugfx_helper", "random", "sleep", "buttons"]
___dependencies___ = ["app", "ugfx_helper", "sleep", "buttons"]
import app, ugfx, ugfx_helper, buttons, sleep, time, random
from tilda import Buttons

View File

@ -17,7 +17,7 @@ They also *may*:
"""
___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
from app import App

View File

@ -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]

View File

@ -1,7 +1,7 @@
"""Tests for random lib"""
___license___ = "MIT"
___dependencies___ = ["upip:unittest", "random"]
___dependencies___ = ["upip:unittest"]
import unittest
from random import *

View File

@ -3,7 +3,7 @@
"""
___name___ = "Screen Party"
___license___ = "MIT"
___dependencies___ = ["ugfx_helper", "sleep", "random"]
___dependencies___ = ["ugfx_helper", "sleep"]
___categories___ = ["Homescreens"]
___bootstrapped___ = False

View File

@ -3,9 +3,9 @@
___name___ = "Snake"
___license___ = "MIT"
___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
ugfx_helper.init()