Walker's alias method for random objects with different probablities

Category: Python - Miscellaneous

an example, strings A B C or D with probabilities .1 .2 .3 .4 --

abcd = dict( A=1, D=4, C=3, B=2 )
# keys can be any immutables: 2d points, colors, atoms ...
wrand = Walkerrandom( abcd.values(), abcd.keys() )
wrand.random() # each call -> "A" "B" "C" or "D"
# fast: 1 randint(), 1 uniform(), table lookup Date: 10 May, 2012


Random Number - Walker S Alias

Homepage: http://code.activestate.com/recipes/576564-walkers-alias-method-for-random-objects-with-diffe/?in=lang-python

Developer: denis

License: Freeware

Operating System: Windows

Add a Comment

all are required fields

     
What do you think of this resource?

Select Your Rate:

Votes:0

 

Related Scripts Download

A random Number generator list.

developer Developer: dreamincode.net
license License: Freeware
operating systems Operating System: All


Replace 1 and 10 with the range you want to pick a number between.

developer Developer: snippets.dzone.com
license License: Freeware
operating systems Operating System: Windows, Linux


Make a variable be equal to any number between to set digits.

developer Developer: dreamincode.net
license License: Freeware
operating systems Operating System: Windows


A powerful pseudorandom number generator wrapped in a user friendly class.

developer Developer: dreamincode.net
license License: Freeware
operating systems Operating System: Windows, Linux, BSD, Solaris


This is a class that allows you to set up an arbitrary probability distribution function and generate random numbers that follow that arbitrary distribution.

developer Developer: Kaushik Ghose
license License: Freeware
operating systems Operating System: Windows


From this great tutorial

For two corelated variables, the formula is much as one would get from intuition about the meaning of correlation with some twist due to normalizing the standard deviation:
$X_3 = alpha X_1 + sqrt{1-alpha^2} X_2$
Where $X_1$ and $X_2$ are two independent random variables, and $alpha$ is the coefficient of correlation between $X_1$ and $X_3$.

developer Developer: Kaushik Ghose
license License: Freeware
operating systems Operating System: Windows


Functions for converting bwtween RGB and HSV color space.

developer Developer: Victor Lin
license License: Freeware
operating systems Operating System: Windows


A server program that listens to a client program for logins and inserts the info into a MySQL database.

developer Developer: Kish
license License: Freeware
operating systems Operating System: Windows