
! Generateur de nombre aleatoire extrait de numerical recipes f90

	module random	

contains
	function ran(idum)

	implicit none

	integer, parameter :: k4b=selected_int_kind(9)
	integer(k4b), intent(inout) :: idum
	real :: ran
	integer(k4b), parameter :: ia=16807, im=2147483647, iq=127773, ir=2836
	real, save :: am
	integer(k4b), save :: ix=-1,iy=-1,k

	if (idum <= 0 .or. iy < 0) then
		am=nearest(1.0,-1.0)/im
	 	iy=ior(ieor(888889999,abs(idum)),1)
		ix=ieor(777755555,abs(idum))
		idum=abs(idum)+1
	endif

	ix=ieor(ix,ishft(ix,13))
	ix=ieor(ix,ishft(ix,-17))
	ix=ieor(ix,ishft(ix,5))
	k=iy/IQ
	iy=IA*(iy-k*IQ)-IR*k
	if (iy < 0) iy=iy+IM
	ran=am*ior(iand(IM,ieor(ix,iy)),1)
	
	end function
	end module
