user9639111
user9639111

Reputation:

How to round off ten random numbers in array?

Trying to generate ten numbers which are random and without decimal point.

my @randoms = map { rand } (1..10)

This code returns ten random numbers yet with decimal like 0.218220758325518.

I want round off these numbers.

Need a help. Thanks.

Upvotes: 3

Views: 78

Answers (1)

choroba
choroba

Reputation: 241808

rand can take a parameter that specifies the supremum of the generated numbers. Just call int to truncate it:

my @randoms = map int rand 20, 1 .. 10;

It generates numbers in the range 0 .. 19.

Upvotes: 4

Related Questions