Another way,
my @c = (1,2,3); my @d = (1,2);
print join '',$c[int rand @c],$d[int rand @d];
This could generate arbitrary random string other than the numbers of "1 2 3"
or "1 2".
ie,the original contents could be:
my @c = qw(a,b,c);
my @d = qw(4,5,6);
>
>Hello, I need to generate two random
On 3/16/07, John W. Krahn <[EMAIL PROTECTED]> wrote:
snip
> my $num = int rand 3 + 1;
That will return either 0, 1, 2 or 3. The addition has higher precedence.
snip
Yeah, I saw that after I posted. That is what I get for posting untested code.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
Fo
On 3/16/07, Chas Owens <[EMAIL PROTECTED]> wrote:
snip
If you need a better pseudo-random number than rand can provide and
you are using Linux (or possibly other unix like operating systems)
you can read from /dev/urandom
snip
I should have hit CPAN first. The Crypt::Random* module provides a
Chas Owens wrote:
> On 3/16/07, Grant <[EMAIL PROTECTED]> wrote:
>> Hello, I need to generate two random numbers. One should be a 1, 2,
>> or 3, and the other should be a 1 or 2. How can I do that?
>
> That depends on your needs. The rand function creates decent quality
> pseudo-random numbers
On 3/16/07, Chas Owens <[EMAIL PROTECTED]> wrote:
snip
my $num = int rand 3 + 1;
snip
oops, that should be
my $num = int rand(3) + 1;
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/
On 3/16/07, Grant <[EMAIL PROTECTED]> wrote:
Hello, I need to generate two random numbers. One should be a 1, 2,
or 3, and the other should be a 1 or 2. How can I do that?
- Grant
That depends on your needs. The rand function creates decent quality
pseudo-random numbers (it calls srand with
Grant wrote:
> Hello,
Hello,
> I need to generate two random numbers. One should be a 1, 2,
> or 3,
int( rand 3 ) + 1
> and the other should be a 1 or 2.
int( rand 2 ) + 1
perldoc -f int
perldoc -f rand
John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
Hello, I need to generate two random numbers. One should be a 1, 2,
or 3, and the other should be a 1 or 2. How can I do that?
- Grant
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/