*
* $Id: npoiss.F,v 3.1.1.1 2002/07/11 16:02:01 cafagna Exp $
*
* $Log: npoiss.F,v $
* Revision 3.1.1.1  2002/07/11 16:02:01  cafagna
* First GPAMELA release on CVS
*
*
*CMZ :  3.00/00 06/04/2001  11.21.19  by  Marialuigia Ambriola
*-- Author :    Marialuigia Ambriola   05/04/2001
      INTEGER FUNCTION NPOISS(X)
**************************************
* Simulate the Poisson distribution
* From data particle book vol. 15 2000
**************************************
      REAL U(1),A,X
      INTEGER K,N
      NPOISS=0
      K=1
      A=1.
c ml26/03/04 100  U=RNDM(1)
 100  CALL GRNDM(U,1)
      A=U(1)*A
      IF(A.LT.EXP(-X)) THEN
         N=K-1
      ELSE
         K=K+1
         GOTO 100
      ENDIF
      NPOISS=N
      RETURN
      END
