Top-rated recipes tagged "random_number" Code RecipesGenerating random numbers with arbitrary distribution (Python) 2008-11-05T07:52:39-08:00Kaushik Ghose <p style="color: grey"> Python recipe 576556 by <a href="/recipes/users/4166965/">Kaushik Ghose</a> (<a href="/recipes/tags/matplotlib/">matplotlib</a>, <a href="/recipes/tags/random_number/">random_number</a>). </p> <p>This is a class that allows you to set up an arbitrary probability distribution function and generate random numbers that follow that arbitrary distribution.</p> The many uses of randomness - Part 2 (Python) 2016-07-17T17:26:47-07:00Vasudev Ram <p style="color: grey"> Python recipe 580690 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/random/">random</a>, <a href="/recipes/tags/random_number/">random_number</a>, <a href="/recipes/tags/simulation/">simulation</a>, <a href="/recipes/tags/testing/">testing</a>). </p> <p>This is the second recipe in the series about the uses of randomness in Python. The first recipe is here:</p> <p><a href="" rel="nofollow"></a></p> <p>This second recipe shows some uses of random numbers to generate random characters and random strings of various categories, and some purposes for which these generated strings can be used in testing.</p> FeatureClassRandomizer (Python) 2012-08-07T15:35:23-07:00Dale Lindeman <p style="color: grey"> Python recipe 578237 by <a href="/recipes/users/4183096/">Dale Lindeman</a> (<a href="/recipes/tags/randomization/">randomization</a>, <a href="/recipes/tags/random_number/">random_number</a>). </p> <p>Generates a randomized list of unique IDs and iteratively assigns values to features in a featureclass.</p> Generate an alpha-numeric password salt (PHP) 2010-02-25T14:07:08-08:00Jayesh Sheth <p style="color: grey"> PHP recipe 577071 by <a href="/recipes/users/4173165/">Jayesh Sheth</a> (<a href="/recipes/tags/md5/">md5</a>, <a href="/recipes/tags/password/">password</a>, <a href="/recipes/tags/random_number/">random_number</a>, <a href="/recipes/tags/salt/">salt</a>). </p> <p>Generate an alpha-numeric password salt (with a default of 32 characters)</p> Walker's alias method for random objects with different probablities (Python) 2008-11-16T15:05:51-08:00denis <p style="color: grey"> Python recipe 576564 by <a href="/recipes/users/4168005/">denis</a> (<a href="/recipes/tags/random_number/">random_number</a>, <a href="/recipes/tags/walker_s_alias/">walker_s_alias</a>). </p> <p>an example, strings A B C or D with probabilities .1 .2 .3 .4 --</p> <pre class="prettyprint"><code>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 -&gt; "A" "B" "C" or "D" # fast: 1 randint(), 1 uniform(), table lookup </code></pre> Generating correlated random numbers (Python) 2008-09-21T21:21:52-07:00Kaushik Ghose <p style="color: grey"> Python recipe 576512 by <a href="/recipes/users/4166965/">Kaushik Ghose</a> (<a href="/recipes/tags/matplotlib/">matplotlib</a>, <a href="/recipes/tags/random_number/">random_number</a>). </p> <p>From this great <a href="">tutorial</a></p> <p>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$.</p> <p>In a more general sense: <br /> Let $C$ be the correlation matrix desired. Let $X_1, X_2..., X_N$ be $N$ independent random variables arranged in a row matrix $R = [X_1, X_2,....,X_N]$. Then $Q = RU$ where $U^TU = C$ gives us $N$ random variables $Q = [Y_1, Y_2, ..., Y_N]$ with the required property.</p> The many uses of randomness - Part 1 (Python) 2016-06-01T19:36:28-07:00Vasudev Ram <p style="color: grey"> Python recipe 580674 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/python2/">python2</a>, <a href="/recipes/tags/random/">random</a>, <a href="/recipes/tags/random_number/">random_number</a>). </p> <p>This recipe shows some of the many uses of random numbers, using the random function from the random module from Python's standard library. A subsequent recipe or two will show other uses, both of other functions from the module, and for other purposes.</p> <p>The uses shown in this recipe have to do with using random float values, and scaling them and offsetting them, and also how to get a repeated/predictable series of random numbers.</p>