Skip site navigation (1)Skip section navigation (2)
Date:      22 Nov 2001 19:20:32 -0800
From:      Ken McGlothlen <mcglk@artlogix.com>
To:        freebsd-questions@freebsd.org
Subject:   Re: Quick question
Message-ID:  <87pu6a2mwv.fsf@ralf.artlogix.com>
In-Reply-To: <034601c173cb$8edfee00$a50410ac@olmct.net>
References:  <034601c173cb$8edfee00$a50410ac@olmct.net>

next in thread | previous in thread | raw e-mail | index | archive | help
"Andre` Niel Cameron" <AndreC@Axxs.net> writes:

| Anyone know how to get a whole random number in perl?
| 
| rand(18) always gives decimals I need just like 12 or 7 anyone know?

Traditionally, most rand()-style functions return a decimal of 0<=x<1.  Perl
gives you a bit better, giving you a rand(n) function which will return 0<=x<n.

In general, you'd probably use

        int(rand(18))

to truncate the value.  This will return a value of 0..17.  If you want 1..18,
just add one.

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?87pu6a2mwv.fsf>