NONMEM Users Network Archive

Hosted by Cognigen

RE: How to generate a random number with $EST

From: Fidler,Matt,FORT WORTH,R&D <Matt.Fidler>
Date: Mon, 14 Mar 2011 09:10:56 -0500


I'm also curious why you wish to generate random numbers. However, FORTR=
AN has a built-in uniform random number generator:

I'm assuming you wish to use a uniform distribution, so this should work ju=
st fine.

However, if you wish to generate Normal deviates, the procedure is slightly=
 more complicated. You can transform uniform deviates to normal deviates u=
sing the Box-Muller method. The basic idea is to take two uniform deviates=
 from -1 to 1, until they are in the unit circle. When they are, you can t=
ransform them to two normal deviates; The second deviate is saved for the =
next call.

Fortran 90 code is available in Numeric Recipes in Fortran on page 279-280,=


From: owner-nmusers
 Behalf Of Nick Holford
Sent: Monday, March 14, 2011 4:09 AM
To: nmusers
Subject: Re: [NMusers] How to generate a random number with $EST


I have no idea why you want to do this but if you want to have the same ran=
dom number at every time then the simplest and most efficient way to do thi=
s is to create the random number as a data item in your data set. You can u=
se the rand() function in Excel to generate a pseudo-random uniform sample =
at each time. It is a waste of computer cycles to have to keep calling the =
random number generator for every record if you want the same random numbe=
r value.

On the other hand if you want a different random number every time you reac=
h a particular record then that is a more complicated matter. I expect it c=
an be done with a verbatim code call but I do not know how. Perhaps you can=

It would be interesting to know why you want the random number when you are=
 not doing simulation.

Best wishes,


On 14/03/2011 10:32 a.m., Nieves Vélez de Mendizabal wrote:
Dear NONMEM Users,

I'm developing a model with NONMEM6|7. In this model, I need to generate a =
random number at every time step. The problem is that the use of the functi=
on "CALL RANDOM (2,R)" is supposed to be only for simulation, isn't it?
Thus, is it possible to generate a random number at every time step with NO=
NMEM? Does anybody know how?
This is part of the code that does not work (it's not working because the c=
ondition ICALL.EQ.4 never happens and for that it's not getting into the "i=
f", but on the other hand, in order to use the function RANDOM(2,R), such f=
unction requires ICALL.EQ.4):
                CALL RANDOM (2,R) ;Rand number in[0,1[
T=2 MSFO=msfo3

Thank you!



Nieves Velez de Mendizabal, Ph.D

Departamento de Farmacia y Tecnología Farmacéutica

Facultad de Farmacia

Universidad de Navarra

Phone: (+34) 658 732 851

Phone: (+34) 948 255 400 ext. 5827




Nick Holford, Professor Clinical Pharmacology

Dept Pharmacology & Clinical Pharmacology

University of Auckland,85 Park Rd,Private Bag 92019,Auckland,New Zealand

tel:+64(9)923-6730 fax:+64(9)373-7090 mobile:+64(21)46 23 53

email: n.holford

This e-mail (including any attachments) is confidential and may be legally =
privileged. If you are not an intended recipient or an authorized represent=
ative of an intended recipient, you are prohibited from using, copying or d=
istributing the information in this e-mail or its attachments. If you have =
received this e-mail in error, please notify the sender immediately by retu=
rn e-mail and delete all copies of this message and any attachments.

Thank you.

Received on Mon Mar 14 2011 - 10:10:56 EDT

The NONMEM Users Network is maintained by ICON plc. Requests to subscribe to the network should be sent to:

Once subscribed, you may contribute to the discussion by emailing: