Vega strike Python Modules doc
0.5.1
Documentation of the " Modules " folder of Vega strike
|
Data Structures | |
class | Random |
Functions | |
def | seed |
--------------—— core generator -------------—— More... | |
def | random |
def | getstate |
def | setstate |
def | jumpahead |
def | whseed |
def | __getstate__ |
-— Methods below this point do not need to be overridden when -— subclassing for the purpose of using a different core generator. More... | |
def | __setstate__ |
def | randrange |
--------------—— integer methods -------------—— More... | |
def | randint |
def | choice |
--------------—— sequence methods -------------—— More... | |
def | shuffle |
def | uniform |
-----------——— real-valued distributions ----------——— More... | |
def | normalvariate |
-----------------— normal distribution -----------------— More... | |
def | lognormvariate |
-----------------— lognormal distribution -----------------— More... | |
def | cunifvariate |
-----------------— circular uniform -----------------— More... | |
def | expovariate |
-----------------— exponential distribution -----------------— More... | |
def | vonmisesvariate |
-----------------— von Mises distribution -----------------— More... | |
def | gammavariate |
-----------------— gamma distribution -----------------— More... | |
def | stdgamma |
def | gauss |
-----------------— Gauss (faster alternative) -----------------— More... | |
def | betavariate |
-----------------— beta -----------------— See http://sourceforge.net/bugs/?func=detailbug&bug_id=130030&group_id=5470 for Ivan Frohne's insightful analysis of why the original implementation: More... | |
def | paretovariate |
-----------------— Pareto -----------------— More... | |
def | weibullvariate |
-----------------— Weibull -----------------— More... | |
Variables | |
float | _pi = 3.1415926536 |
float | _e = 2.7182818284590451 |
list | __all__ |
int | NV_MAGICCONST = 4 |
float | TWOPI = 2.0 |
tuple | LOG4 = _log(4.0) |
float | SG_MAGICCONST = 1.0 |
tuple | _inst = Random() |
seed = _inst.seed | |
random = _inst.random | |
uniform = _inst.uniform | |
randint = _inst.randint | |
choice = _inst.choice | |
randrange = _inst.randrange | |
shuffle = _inst.shuffle | |
normalvariate = _inst.normalvariate | |
lognormvariate = _inst.lognormvariate | |
cunifvariate = _inst.cunifvariate | |
expovariate = _inst.expovariate | |
vonmisesvariate = _inst.vonmisesvariate | |
gammavariate = _inst.gammavariate | |
stdgamma = _inst.stdgamma | |
gauss = _inst.gauss | |
betavariate = _inst.betavariate | |
paretovariate = _inst.paretovariate | |
weibullvariate = _inst.weibullvariate | |
getstate = _inst.getstate | |
setstate = _inst.setstate | |
jumpahead = _inst.jumpahead | |
whseed = _inst.whseed | |
_seed | |
gauss_next | |
Random variable generators. integers -------- uniform within range sequences --------- pick random element generate random permutation distributions on the real line: ------------------------------ uniform normal (Gaussian) lognormal negative exponential gamma beta distributions on the circle (angles 0 to 2pi) --------------------------------------------- circular uniform von Mises Translated from anonymously contributed C/C++ source. Multi-threading note: the random number generator used here is not thread- safe; it is possible that two calls return the same random value. However, you can instantiate a different instance of Random() in each thread to get generators that don't share state, then use .setstate() and .jumpahead() to move the generators to disjoint segments of the full period. For example, def create_generators(num, delta, firstseed=None): ""\"Return list of num distinct generators. Each generator has its own unique segment of delta elements from Random.random()'s full period. Seed the first generator with optional arg firstseed (default is None, to seed from current time). ""\" from random import Random g = Random(firstseed) result = [g] for i in range(num - 1): laststate = g.getstate() g = Random() g.setstate(laststate) g.jumpahead(delta) result.append(g) return result gens = create_generators(10, 1000000) That creates 10 distinct generators, which can be passed out to 10 distinct threads. The generators don't share state so can be called safely in parallel. So long as no thread calls its g.random() more than a million times (the second argument to create_generators), the sequences seen by each thread will not overlap. The period of the underlying Wichmann-Hill generator is 6,953,607,871,644, and that limits how far this technique can be pushed. Just for fun, note that since we know the period, .jumpahead() can also be used to "move backward in time": >>> g = Random(42) # arbitrary >>> g.random() 0.25420336316883324 >>> g.jumpahead(6953607871644L - 1) # move *back* one >>> g.random() 0.25420336316883324
def random.__getstate__ | ( | self) |
-— Methods below this point do not need to be overridden when -— subclassing for the purpose of using a different core generator.
-----------------— pickle support ----------------—
def random.__setstate__ | ( | self, | |
state | |||
) |
def random.betavariate | ( | self, | |
alpha, | |||
beta | |||
) |
-----------------— beta -----------------— See http://sourceforge.net/bugs/?func=detailbug&bug_id=130030&group_id=5470 for Ivan Frohne's insightful analysis of why the original implementation:
def betavariate(self, alpha, beta):
y = self.expovariate(alpha) z = self.expovariate(1.0/beta) return z/(y+z)
was dead wrong, and how it probably got that way.
Definition at line 551 of file random.py.
References betavariate.
def random.choice | ( | self, | |
seq | |||
) |
def random.cunifvariate | ( | self, | |
mean, | |||
arc | |||
) |
-----------------— circular uniform -----------------—
Definition at line 385 of file random.py.
References cunifvariate.
def random.expovariate | ( | self, | |
lambd | |||
) |
-----------------— exponential distribution -----------------—
Definition at line 393 of file random.py.
References expovariate.
def random.gammavariate | ( | self, | |
alpha, | |||
beta | |||
) |
-----------------— gamma distribution -----------------—
Definition at line 447 of file random.py.
References gammavariate.
def random.gauss | ( | self, | |
mu, | |||
sigma | |||
) |
def random.getstate | ( | self) |
def random.jumpahead | ( | self, | |
n | |||
) |
Act as if n calls to random() were made, but quickly. n is an int, greater than or equal to 0. Example use: If you have 2 threads and know that each will consume no more than a million random numbers, create two Random objects r1 and r2, then do r2.setstate(r1.getstate()) r2.jumpahead(1000000) Then r1 and r2 will use guaranteed-disjoint segments of the full period.
Definition at line 199 of file random.py.
References jumpahead.
def random.lognormvariate | ( | self, | |
mu, | |||
sigma | |||
) |
-----------------— lognormal distribution -----------------—
Definition at line 380 of file random.py.
References lognormvariate.
def random.normalvariate | ( | self, | |
mu, | |||
sigma | |||
) |
-----------------— normal distribution -----------------—
Definition at line 360 of file random.py.
References normalvariate.
def random.paretovariate | ( | self, | |
alpha | |||
) |
-----------------— Pareto -----------------—
Definition at line 562 of file random.py.
References paretovariate.
def random.randint | ( | self, | |
a, | |||
b | |||
) |
def random.random | ( | self) |
def random.randrange | ( | self, | |
start, | |||
stop = None , |
|||
step = 1 , |
|||
int = int , |
|||
default = None |
|||
) |
--------------—— integer methods -------------——
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. Do not supply the 'int' and 'default' arguments.
Definition at line 278 of file random.py.
References randrange.
def random.seed | ( | self, | |
a = None |
|||
) |
--------------—— core generator -------------——
Initialize internal state from hashable object. None or no argument seeds from current time. If a is not None or an int or long, hash(a) is used instead. If a is an int or long, a is used directly. Distinct values between 0 and 27814431486575L inclusive are guaranteed to yield distinct internal states (this guarantee is specific to the default Wichmann-Hill generator).
Definition at line 128 of file random.py.
References seed.
def random.setstate | ( | self, | |
state | |||
) |
def random.shuffle | ( | self, | |
x, | |||
random = None , |
|||
int = int |
|||
) |
x, random=random.random -> shuffle list x in place; return None. Optional arg random is a 0-argument function returning a random float in [0.0, 1.0); by default, the standard random.random. Note that for even rather small len(x), the total number of permutations of x is larger than the period of most random number generators; this implies that "most" permutations of a long sequence can never be generated.
Definition at line 331 of file random.py.
References shuffle.
def random.stdgamma | ( | self, | |
alpha, | |||
ainv, | |||
bbb, | |||
ccc | |||
) |
def random.uniform | ( | self, | |
a, | |||
b | |||
) |
def random.vonmisesvariate | ( | self, | |
mu, | |||
kappa | |||
) |
-----------------— von Mises distribution -----------------—
Definition at line 405 of file random.py.
References vonmisesvariate.
def random.weibullvariate | ( | self, | |
alpha, | |||
beta | |||
) |
-----------------— Weibull -----------------—
Definition at line 570 of file random.py.
References pre.compile(), getstate, jumpahead, sre_parse.max, sre_parse.min, setstate, and weibullvariate.
def random.whseed | ( | self, | |
a = None |
|||
) |
Seed from hashable object's hash code. None or no argument seeds from current time. It is not guaranteed that objects with distinct hash codes lead to distinct internal states. This is obsolete, provided for compatibility with the seed routine used prior to Python 2.1. Use the .seed() method instead.
Definition at line 242 of file random.py.
References whseed.
list __all__ |