RandomVariate

RandomVariate[dist]

gives a pseudorandom variate from the symbolic distribution dist.

RandomVariate[dist,n]

gives a list of n pseudorandom variates from the symbolic distribution dist.

RandomVariate[dist,{n1,n2,}]

gives an n1× n2× array of pseudorandom variates from the symbolic distribution dist.

Details and Options

  • RandomVariate can generate random variates for continuous, discrete, or mixed distributions specified as a symbolic distribution.
  • RandomVariate gives a different sequence of pseudorandom numbers whenever you run the Wolfram Language. You can start with a particular seed using SeedRandom.
  • With the setting WorkingPrecision->p, random numbers of precision p will be generated.

Examples

open allclose all

Basic Examples  (5)

Simulate a continuous probability distribution:

Simulate a discrete probability distribution:

Simulate a multivariate continuous distribution:

Simulate a multivariate discrete distribution:

Generate random numbers from a mixture distribution:

Scope  (22)

Basic Uses  (5)

Use RandomVariate to generate arrays of different sizes and dimensions:

A vector:

A matrix:

A rank-3 tensor:

Generate high-precision random variates:

Use SeedRandom to get repeatable random values:

Generate random variates for a univariate continuous distribution:

Discrete univariate distribution:

Continuous multivariate distribution:

Discrete multivariate distribution:

Generate random variates for a quantity distribution:

Generate array of variates:

Generate random vectors:

Parametric Distributions  (4)

Generate random variates for univariate continuous distributions:

Generate random variates for univariate discrete distributions:

Generate random variates for multivariate continuous distributions:

Generate random variates for multivariate discrete distributions:

Nonparametric Distributions  (4)

Generate random variates for a univariate EmpiricalDistribution:

Using a multivariate empirical distribution:

Using a univariate HistogramDistribution:

A multivariate histogram distribution:

Using a univariate KernelMixtureDistribution:

Using censored data with SurvivalDistribution:

Derived Distributions  (9)

Generate random variates for a TransformedDistribution:

An equivalent way of generating the same random variates:

Generate random variates for a ProductDistribution:

An equivalent way of generating the same random variates:

Using a component mixture of normal distributions:

Parameter mixture of exponential distributions:

Compare the variance of the sample with the variance of the distribution:

Truncated normal distribution:

Censored exponential distribution:

Compare the kurtosis for the sample with the kurtosis for the distribution:

Marginal distribution:

Compute probabilities using the sample and the marginal distribution:

Copula distribution:

Compare the value of a moment for the sample with that for the copula distribution:

Formula distribution:

Options  (1)

WorkingPrecision  (1)

By default MachinePrecision random numbers are generated for continuous distributions:

Use the WorkingPrecision option to generate numbers with arbitrary precision:

Applications  (30)

Pictures of Random Data  (6)

Generate random data for a continuous distribution and compare its histogram to the PDF:

Generate random data for a discrete distribution and compare its histogram to the PDF:

Generate random data for a bivariate distribution and compare its histogram to the PDF:

Compare the plots of random data for continuous multivariate distributions:

Consider vectors with standard normal components:

The angle will follow a uniform distribution:

The norm will follow a Rayleigh distribution:

Consider three-dimensional vectors with standard normal components:

The angle in spherical coordinates follows a uniform distribution:

The norm will follow a distribution:

Distribution Properties  (5)

Verify the Poisson approximation to the binomial distribution using random variates:

Define a truncated triangular distribution:

Generate random numbers from this distribution:

Mean, variance, and kurtosis:

Moments:

Probabilities and expectations:

Simulate the distribution of a function of a random variable:

Compare the mean and variance of the sample with those for the distribution:

Generate random data from a normal distribution:

Define nonparametric distributions using this data:

Compare the mean and variance of these distributions:

Estimate an unknown slice distribution of a random process:

Slice distribution is unknown:

Generate a random sample of paths:

Visualize its probability density function:

Test if it fits a standard normal distribution:

Random Experiments  (4)

Simulate 10 throws of a fair six-sided die:

Simulate seven throws of a pair of fair six-sided dice:

A coin-tossing experiment consists of tossing a fair coin repeatedly until a head results. Simulate the process:

A radioactive material on average emits 3.2 -particles per second; show the distribution. Simulate a typical particle-count experiment for 10 minutes:

Simulate a symmetric random walk with values -1 and 1:

Estimation and Hypothesis Testing  (3)

Generate random data for a normal distribution:

Estimate the distribution parameters using the random data:

Generate high-precision random data for a component mixture distribution:

Estimate the mixture probabilities, assuming the component distributions are known:

Given a binormal sample, the -statistic follows a shifted FisherZDistribution:

Generate the distribution of -statistics for binormal samples of size :

Visually compare the -statistic distribution to a shifted FisherZDistribution:

DistributionFitTest confirms the result:

Quality  (3)

Suppose there are 5 defective items in a batch of 10 items, and 6 items are selected for testing. Simulate the number of defective items found:

Out of 10 bulbs produced, one is defective. Simulate the production of 100 bulbs:

Find the percentage of good bulbs:

Find the average number of good bulbs per batch of 100:

Find the probability that a randomly selected bulb is good:

A shipment of products is inspected in batches of 60 and each batch is inspected up to rejection when the 10^(th) defective item is found. What is the probability of a batch being rejected if 20% of the items are defective?

Alternatively, compute the same result by truncating the distribution:

Simulate the number of non-defective products in rejected batches:

Illustrate the ratio in each batch:

Find the average ratio of non-defective to defective products in rejected batches:

Traffic  (3)

The number of customers arriving at a service desk follows PoissonDistribution with mean 0.6, and the number of customers already in line before the service desk opens follows PoissonDistribution with mean 5. The number of customers served until there is no one in line follows PoissonConsulDistribution:

Plot the probability mass function:

Simulate numbers of customers served at 30 busy periods:

The average number of accidents in a city is 100 per day. Simulate the daily accidents:

The expected number of raindrops falling into a bucket in a five-second interval is 20. Simulate the raindrop count for each five-second interval:

Finance  (1)

Assuming daily logarithmic return of the stock market follows a stable distribution, simulate and visualize stock prices over a period of 5 years:

Other Applications  (5)

RandomVariate can generate complex numbers if necessary:

Evaluate an integral numerically using a Monte Carlo scheme:

Approximate with an interpolating function defined with uniformly distributed random nodes:

Interpolate between the nodes:

Find the value of the integral using the interpolating function:

Compare with the value obtained using the original function:

Sample a Gaussian symmetric matrix:

Fit WignerSemicircleDistribution to its eigenvalues:

Compare the histogram of the eigenvalues with the PDF:

The heights of females in the United States follow normal distribution with mean 64 inches and standard deviation of 2 inches, while the heights of males in the United States follow normal distribution with mean 70 inches and standard deviation of 2 inches. If the population ratio of males to females is 1:1, then the heights of the whole population have the following bimodal distribution:

Simulate the typical distribution of heights in a town of population 100:

Find the probability that a person is at least 73 inches tall:

A basketball player shoots free throws until he hits 4 of them. His probability of scoring in any one of them is 0.7. Simulate the process:

Find the number of shots the player is expected to shoot:

Properties & Relations  (17)

RandomInteger generates uniform discrete random variates:

RandomReal generates uniform continuous variates:

RandomChoice generates random choices with replacement from a list:

RandomSample generates random choice without replacement from a list:

RandomPrime generates a random prime number:

RandomImage generates a random image:

RandomGraph generates a random graph:

RandomFunction generates a path for a random process:

Use RandomVariate to generate a sample for a time slice of the process:

Test whether the mean or median is zero by using LocationTest:

Compare means or medians for several datasets using LocationEquivalenceTest:

Test whether two datasets have the same variance by using VarianceTest:

Test whether several datasets have the same variance by using VarianceEquivalenceTest:

Use DistributionFitTest to test goodness of fit between random data and a distribution:

Estimate distribution parameters from random data using EstimatedDistribution:

Estimate nonparametric distributions from random data:

Compare random data to distributions using statistical visualization functions:

Compare multiple distributions using statistical charts:

Plot histograms from random data:

Plot smooth kernel density estimates from data:

Possible Issues  (3)

The speed of random variate generation may depend on the distribution:

The WorkingPrecision option is ignored for discrete distributions:

The result from RandomVariate may include infinite quantities:

Using a different level of precision avoids the problem in this case:

Wolfram Research (2010), RandomVariate, Wolfram Language function, https://reference.wolfram.com/language/ref/RandomVariate.html.

Text

Wolfram Research (2010), RandomVariate, Wolfram Language function, https://reference.wolfram.com/language/ref/RandomVariate.html.

CMS

Wolfram Language. 2010. "RandomVariate." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/RandomVariate.html.

APA

Wolfram Language. (2010). RandomVariate. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/RandomVariate.html

BibTeX

@misc{reference.wolfram_2024_randomvariate, author="Wolfram Research", title="{RandomVariate}", year="2010", howpublished="\url{https://reference.wolfram.com/language/ref/RandomVariate.html}", note=[Accessed: 21-November-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_randomvariate, organization={Wolfram Research}, title={RandomVariate}, year={2010}, url={https://reference.wolfram.com/language/ref/RandomVariate.html}, note=[Accessed: 21-November-2024 ]}