[Tutor] Data persistence problem

Fábio Santos fabiosantosart at gmail.com
Fri Jun 21 12:00:48 CEST 2013


On 21 Jun 2013 07:36, "Arijit Ukil" <arijit.ukil at tcs.com> wrote:
>
> I have following random number generation function
>
> def rand_int ():
>     rand_num = int(math.ceil (random.random()*1000))
>     return rand_num
>
> I like to make the value of rand_num (return of rand_int) static/
unchanged after first call even if it is called multiple times. If x=
 rand_int () returns 45 at the first call, x should retain 45 even in
multiple calls.
> Pls help.
>

Use a variable.

_the_num = random.randint(......)
def rand_int():
    return _the_num
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130621/684285de/attachment.html>


More information about the Tutor mailing list