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.

  • $\begingroup$ What's a "top hat distribution"? $\endgroup$ 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$ 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$ 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$ Jun 4, 2020 at 4:05


Your Answer

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

Browse other questions tagged or ask your own question.