How can I generate random (int) values with specific size and mean?

Marim medhat

I need to generate 1000 samples (int) with average 2. Do you think such a function already exists in python?

Ari Cooper-Davis

NumPy's random.randint(low, high=None, size=None, dtype=int) generates "random integers from the “discrete uniform” distribution of the specified dtype in the “half-open” interval [low, high)".

Therefore, to generate random integers with mean of 2 just make sure that the interval you specify is centred on 2.

>>> import numpy as np
>>> np.random.randint(0,5,10000000).mean()
1.999827
>>> np.random.randint(-10,15,10000000).mean()
2.000426

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Generate n random values from a specific mean and range values

How can I generate a random int using the "crypto/rand" package?

How can I generate random number in specific range in Android?

How can I generate different random values in Haskell?

How can I replicate specific random draws in loops of different size?

How can I generate random cubes around specific point in random positions?

How do I generate a string of random ASCII printable characters with a specific size in Rust?

How do I generate a random int number?

How to generate random numbers to satisfy a specific mean and median in python?

How can i generate random variables using np.random.zipf for a given range of values?

How can we generate random values in Scrypto?

How can I create a dynamic array with different random values in random size?

How to generate random sample of size 80 with specific split ratio in R?

How can I generate random alphanumeric strings?

How can I generate random shades of an RGB?

How can I generate random items with conditions?

How do I generate random numbers with a mean in C++?

How can I generate a random number for each group of values in a column in Python?

How can I generate a matrix with random values based from a larger matrix in Python?

How can I generate n random values from a bimodal distribution in Python?

How can I make my discord bot generate a random number between 2 given values?

How do I generate a random color in a specific range?

How do I generate a specific amount of random numbers?

How can I generate random files with size 1mb each from 1-500 using linux shell script

How to generate a random int in C?

How to generate random Int in Haskell?

How can I generate random numbers in slabs of a range in Python3 or in a specific interval of range in Python3?

How can i generate random char from variable

How can I generate pseudo-random "readable" strings in Java?

TOP Ranking

HotTag

Archive