in reply to Re: Make random numbers
in thread Make random numbers
There are 2 minor details to be addressed. The rand(1000) function will return float values from 0 and never reaching 1000. So we need to chop off the fractional part - that will yield ints from 0..999. To get the desired range, adding a constant offset of 1 will do the job.
#!/usr/bin/perl use strict; use warnings; print "",int(rand(1000))+1,"\n" for (1..100);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Make random numbers
by Eily (Monsignor) on Dec 07, 2018 at 09:35 UTC | |
by Marshall (Canon) on Dec 07, 2018 at 10:01 UTC | |
by syphilis (Archbishop) on Dec 07, 2018 at 11:15 UTC | |
by Ratazong (Monsignor) on Dec 07, 2018 at 12:40 UTC | |
by syphilis (Archbishop) on Dec 07, 2018 at 13:03 UTC | |
by Marshall (Canon) on Dec 09, 2018 at 19:58 UTC | |
by AnomalousMonk (Archbishop) on Dec 09, 2018 at 20:17 UTC | |
|