示例#1
0
文件: model.py 项目: griels/pypy-sc
class W_AbstractObjectWithIdentityHash(W_Object):
    """Object with explicit hash (ie all except small
    ints and floats)."""
    #XXX maybe this is too extreme, but it's very random
    hash_generator = rrandom.Random()
    UNASSIGNED_HASH = sys.maxint

    hash = UNASSIGNED_HASH  # default value

    def setchar(self, n0, character):
        raise NotImplementedError()

    def gethash(self):
        if self.hash == self.UNASSIGNED_HASH:
            self.hash = hash = intmask(self.hash_generator.genrand32()) // 2
            return hash
        return self.hash

    def invariant(self):
        return isinstance(self.hash, int)

    def become(self, w_other):
        if not isinstance(w_other, W_AbstractObjectWithIdentityHash):
            return False
        self.hash, w_other.hash = w_other.hash, self.hash
        return True
示例#2
0
文件: model.py 项目: chyyuu/pygirl
class W_AbstractObjectWithIdentityHash(W_Object):
    #XXX maybe this is too extreme, but it's very random
    hash_generator = rrandom.Random()
    UNASSIGNED_HASH = sys.maxint

    hash = UNASSIGNED_HASH  # default value

    def gethash(self):
        if self.hash == self.UNASSIGNED_HASH:
            self.hash = hash = intmask(self.hash_generator.genrand32()) // 2
            return hash
        return self.hash

    def invariant(self):
        return isinstance(self.hash, int)
示例#3
0
 def __init__(self, space, w_anything):
     self._rnd = rrandom.Random()
     self.seed(space, w_anything)
示例#4
0
# apt-get install libsdl-dev
from pypy.rlib.rsdl import RSDL, RSDL_helper
from pypy.rlib.rarithmetic import r_uint
from pypy.rpython.lltypesystem import lltype, rffi
from pypy.rlib.listsort import TimSort
from pypy.rlib.jit import hint, we_are_jitted, JitDriver, purefunction_promote

#random.randrange(0, up)		# not a replacement for random.uniform
#Choose a random item from range(start, stop[, step]).
#This fixes the problem with randint() which includes the
#endpoint; in Python this is usually not what you want.

if '--pypy' in sys.argv:  # random.random works in pypy, but random.uniform is missing?
    from pypy.rlib import rrandom
    RAND = rrandom.Random()
    RAND.init_by_array([1, 2, 3, 4])

    def random():
        return RAND.random()

    def uniform(start, end):
        return (RAND.random() * (end - start)) - start
else:
    from random import *


def distance(v1, v2):
    dx = v1[0] - v2[0]
    dy = v1[1] - v2[1]
    dz = v1[2] - v2[2]
示例#5
0
文件: bpnn.py 项目: chyyuu/pygirl
#
# Modifications to the original (Armin Rigo):
#   * import random from PyPy's lib, which is Python 2.2's plain
#     Python implementation
#   * starts the Translator instead of the demo by default.

import sys
import math
import time

import autopath
from pypy.rlib import rrandom

PRINT_IT = False

random = rrandom.Random(1)


# calculate a random number where:  a <= rand < b
def rand(a, b):
    return (b - a) * random.random() + a


# Make a matrix (we could use NumPy to speed this up)
def makeMatrix(I, J, fill=0.0):
    m = []
    for i in range(I):
        m.append([fill] * J)
    return m