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 vsrandom.__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 ----------------—
Definition at line 270 of file vsrandom.py.
def vsrandom.__setstate__ | ( | self, | |
state | |||
) |
Definition at line 273 of file vsrandom.py.
def vsrandom.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 vsrandom.py.
References betavariate.
def vsrandom.choice | ( | self, | |
seq | |||
) |
--------------—— sequence methods -------------——
Choose a random element from a non-empty sequence.
Definition at line 327 of file vsrandom.py.
References choice.
def vsrandom.cunifvariate | ( | self, | |
mean, | |||
arc | |||
) |
-----------------— circular uniform -----------------—
Definition at line 385 of file vsrandom.py.
References cunifvariate.
def vsrandom.expovariate | ( | self, | |
lambd | |||
) |
-----------------— exponential distribution -----------------—
Definition at line 393 of file vsrandom.py.
References expovariate.
def vsrandom.gammavariate | ( | self, | |
alpha, | |||
beta | |||
) |
-----------------— gamma distribution -----------------—
Definition at line 447 of file vsrandom.py.
References gammavariate.
def vsrandom.gauss | ( | self, | |
mu, | |||
sigma | |||
) |
-----------------— Gauss (faster alternative) -----------------—
Definition at line 506 of file vsrandom.py.
References gauss.
def vsrandom.getstate | ( | self) |
Return internal state; can be passed to setstate() later.
Definition at line 185 of file vsrandom.py.
References getstate.
def vsrandom.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 vsrandom.py.
References jumpahead.
def vsrandom.lognormvariate | ( | self, | |
mu, | |||
sigma | |||
) |
-----------------— lognormal distribution -----------------—
Definition at line 380 of file vsrandom.py.
References lognormvariate.
def vsrandom.normalvariate | ( | self, | |
mu, | |||
sigma | |||
) |
-----------------— normal distribution -----------------—
Definition at line 360 of file vsrandom.py.
References normalvariate.
def vsrandom.paretovariate | ( | self, | |
alpha | |||
) |
-----------------— Pareto -----------------—
Definition at line 562 of file vsrandom.py.
References paretovariate.
def vsrandom.randint | ( | self, | |
a, | |||
b | |||
) |
Return random integer in range [a, b], including both end points. (Deprecated; use randrange(a, b+1).)
Definition at line 317 of file vsrandom.py.
References randint.
def vsrandom.random | ( | self) |
Get the next random number in the range [0.0, 1.0).
Definition at line 154 of file vsrandom.py.
References random.
def vsrandom.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 vsrandom.py.
References randrange.
def vsrandom.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 vsrandom.py.
References seed.
def vsrandom.setstate | ( | self, | |
state | |||
) |
Restore internal state from object returned by getstate().
Definition at line 189 of file vsrandom.py.
References setstate.
def vsrandom.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 vsrandom.py.
References shuffle.
def vsrandom.stdgamma | ( | self, | |
alpha, | |||
ainv, | |||
bbb, | |||
ccc | |||
) |
def vsrandom.uniform | ( | self, | |
a, | |||
b | |||
) |
-----------——— real-valued distributions ----------———
--------------—— uniform distribution -------------——
Get a random number in the range [a, b).
Definition at line 354 of file vsrandom.py.
References uniform.
def vsrandom.vonmisesvariate | ( | self, | |
mu, | |||
kappa | |||
) |
-----------------— von Mises distribution -----------------—
Definition at line 405 of file vsrandom.py.
References vonmisesvariate.
def vsrandom.weibullvariate | ( | self, | |
alpha, | |||
beta | |||
) |
-----------------— Weibull -----------------—
Definition at line 570 of file vsrandom.py.
References pre.compile(), getstate, jumpahead, sre_parse.max, sre_parse.min, setstate, and weibullvariate.
def vsrandom.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 vsrandom.py.
References whseed.
list __all__ |
Definition at line 80 of file vsrandom.py.
float _e = 2.7182818284590451 |
Definition at line 76 of file vsrandom.py.
tuple _inst = Random() |
Definition at line 639 of file vsrandom.py.
float _pi = 3.1415926536 |
Definition at line 75 of file vsrandom.py.
_seed |
Definition at line 152 of file vsrandom.py.
betavariate = _inst.betavariate |
Definition at line 655 of file vsrandom.py.
choice = _inst.choice |
Definition at line 644 of file vsrandom.py.
cunifvariate = _inst.cunifvariate |
Definition at line 649 of file vsrandom.py.
expovariate = _inst.expovariate |
Definition at line 650 of file vsrandom.py.
gammavariate = _inst.gammavariate |
Definition at line 652 of file vsrandom.py.
gauss = _inst.gauss |
Definition at line 654 of file vsrandom.py.
gauss_next |
Definition at line 193 of file vsrandom.py.
getstate = _inst.getstate |
Definition at line 658 of file vsrandom.py.
jumpahead = _inst.jumpahead |
Definition at line 660 of file vsrandom.py.
tuple LOG4 = _log(4.0) |
Definition at line 98 of file vsrandom.py.
lognormvariate = _inst.lognormvariate |
Definition at line 648 of file vsrandom.py.
normalvariate = _inst.normalvariate |
Definition at line 647 of file vsrandom.py.
int NV_MAGICCONST = 4 |
Definition at line 92 of file vsrandom.py.
paretovariate = _inst.paretovariate |
Definition at line 656 of file vsrandom.py.
randint = _inst.randint |
Definition at line 643 of file vsrandom.py.
random = _inst.random |
Definition at line 641 of file vsrandom.py.
randrange = _inst.randrange |
Definition at line 645 of file vsrandom.py.
seed = _inst.seed |
Definition at line 640 of file vsrandom.py.
setstate = _inst.setstate |
Definition at line 659 of file vsrandom.py.
float SG_MAGICCONST = 1.0 |
Definition at line 101 of file vsrandom.py.
shuffle = _inst.shuffle |
Definition at line 646 of file vsrandom.py.
stdgamma = _inst.stdgamma |
Definition at line 653 of file vsrandom.py.
float TWOPI = 2.0 |
Definition at line 95 of file vsrandom.py.
uniform = _inst.uniform |
Definition at line 642 of file vsrandom.py.
vonmisesvariate = _inst.vonmisesvariate |
Definition at line 651 of file vsrandom.py.
weibullvariate = _inst.weibullvariate |
Definition at line 657 of file vsrandom.py.
whseed = _inst.whseed |
Definition at line 661 of file vsrandom.py.