# Making a histogram of a user defined random variable

Suppose I want to generate a histogram of $n$ trials a slightly complicated random variable in Mathematica. Is there an easy way to do this?

For instance, to make a histogram of a normal variable one can simple use

Histogram[RandomVariate[NormalDistribution[0, 1], 200]]


I want to create a histogram of a more complicated random variable. The random variable comes from random matrix theory, but its specific form is probably not so important. If we call it X, running

Histogram[RandomVariate[X, 200]]


returns

RandomVariate::udist: "The specification X is not a random distribution recognized by the system." Indeed, even running

Histogram[RandomVariate[NormalDistribution[0, 1]^2, 200]]


returns this error message, and I think if I understood what's going wrong in this latter case my problem would be resolved also.

There is a Mathematica help page on the topic, but all the examples of random variables given there are for prepackaged probability distributions.

-
Have you looked at ProbabilityDistribution[] – george2079 Nov 26 '13 at 21:07
What do you mean by NormalDistribution[0, 1]^2? It is square of the probability density function or x^2 where x distributed as NormalDistribution[0, 1]? TransformedDistribution, EmpiricalDistribution and SmoothKernelDistribution can be helpful. Could you provide an example of the distribution? – ybeltukov Nov 26 '13 at 21:09
Break your problem down to pieces and find the smallest piece that you can't get working. Do you need to plot the PDF or do you just need to generate a large number of random variates? It seems to me that you need the latter. In this case Histogram is irrelevant to the question. NormalDistribution[0, 1]^2 is not correct syntax. As george said, look at ProbabilityDistribution. – Szabolcs Nov 26 '13 at 21:09
You don't have a problem with Histogram, you have a problem defining a distribution. Have a look at Create Your Own Distribution Workshop. – Sjoerd C. de Vries Nov 26 '13 at 21:19

Histogram[

Note that the argument to ProbabilityDistribution[] has to be a proper probability density function in the sense that it integrates to unity. (Thats where that 2 Sqrt[π] comes from)