I need a PDF $ f(x) $ to satisfy two conditions. That is, for a given value $B$, the conditions

$$ \int_0^1 f(x)dx = 1-B $$


$$ \int_0^\infty f(x)dx = 1$$


The purpose of this distribution is to generate random integers (using $ \left \lfloor{x}\right \rfloor $) from 0 to infinity, with $ E[x] $ being $B$.

I think I need to use a Gaussian distribution, but I don't know how I'd do this. I know I need to integrate the Gaussian function from 0 to infinity (since I'm not using negative values) and normalise it, but everything I've tried has led me nowhere.

Edit to add details about the actual problem:

I have been assigned to write some code for an astronomy research group at my university for the summer (mostly in Python). One of the assignments I've been given is to write a program that generates an image with a level of background noise and one peak source, to simulate an image of an X ray cluster. The value $B$ is the expected value for a pixel due to the background noise in the image; typically in real images this is of the order of 0.05 (so most pixels have a value of 0, roughly one in twenty have a value of 1, although in theory the value could be very high, hence me needing a more complex distribution).

The code will take an input for $B$ and create random noise on the image from this value.

The reason that I need integers is because the data that the group uses comes from an X ray telescope, so the pixel values on the real images will be integers, because that is the number of X ray photons that the telescope detected in that location during the exposure time, which will be quantized.

I have tried using a Gaussian distribution simply because it best approximates what I want; I have also looked into the binomial and Maxwell-Boltzmann distributions, so if they work as well or better than the Gaussian for this situation, then I'm open to suggestions, but I could not see how they would be more applicable.

  • 1
    $\begingroup$ How does that equation give you expectation $B$? Why do you think it has anything to do with normal distributions? Why do you want to take the integer part of a continuous variate rather than do something else? It seems you might be better off explaining the underlying problem in a bit more detail and letting people suggest approaches, than asking about your attempted solution. $\endgroup$
    – Glen_b
    Aug 10, 2017 at 12:08
  • $\begingroup$ I have edited my question to include more information about what the problem is I'm trying to solve, as well as other information and a minor correction. $\endgroup$ Aug 10, 2017 at 12:26
  • 1
    $\begingroup$ It seems to me like the Poisson distribution does exactly what you're looking for. You can use numpy.random.poisson to sample a value. Is there a reason why it's not suitable? $\endgroup$ Aug 10, 2017 at 16:14
  • $\begingroup$ While a Poisson would seem to be a good choice for background noise, I don't think the OPs first condition will fit with the expectation. With a Poisson($\lambda$) we don't have $P(0)=1-\lambda$ (except approximately); but there's no indication in the question that anything but $P(0)=1-B$ is okay (even if it's only a $0.13\%$ error for $B=1/20$). If the OP is prepared to have the probability of a 0 only be approximately $1-B$ then it should work quite well $\endgroup$
    – Glen_b
    Aug 10, 2017 at 19:50

1 Answer 1


The notion of using some continuous variate on $(0,\infty)$ and discretizing it, or indeed of using the Gaussian distribution is not directly relevant to your problem.

To get a discrete variate with exactly these properties:



that also fits your description in the edit (which implies $P(X=1)=B$) the only possibility is a Bernoulli distribution with parameter $B$.

However, I'd strongly suggest you consider Bridgeburner's suggestion of a Poisson distribution with parameter $B$ even though it only approximately fits your conditions --

With $B=1/20$ you'd have:

$P(X=0) = 0.95123\:$ (which is not $1-B$ exactly)
$P(X=1) = 0.04756$
$P(X=2) = 0.00119$
$P(X>2) = 0.00002$

and has expected value $1/20$. The Poisson would be a common (even standard) choice for background noise of the kind you would appear to actually need.


Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.