0
$\begingroup$

How would I use a random number generator to give random numbers from a top hat distribution in Fortran? I've seen lots of information about how to make a Gaussian random number generator, but not one with a top hat distribution.

$\endgroup$
4
  • $\begingroup$ What's a "top hat distribution"? $\endgroup$ Commented Jun 3, 2020 at 19:29
  • $\begingroup$ If you have a Gaussian random number generator, you can sample it, then if the sampled number is inside (mean-variance,mean+variance) then you return 1, otherwise, you return 0. $\endgroup$ Commented Jun 3, 2020 at 20:32
  • $\begingroup$ Unless, of course, you are talking about uniform distribution over an arbitrary interval. That is just shifting and scaling. $\endgroup$ Commented Jun 3, 2020 at 22:19
  • $\begingroup$ For a given random distribution characterized by some PDF one can find a transformation resulting in a different PDF. So from the standard random generators producing normal and uniform distributions one can derive a transformation producing anything else, including the "hat" function. $\endgroup$ Commented Jun 4, 2020 at 4:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.