I've been experimenting with some shell scripting recently. I'm using the following line of code to create 2 unique random numbers in range 1 to 12
and sort them into ascending numerical order:
numbers=($(jot -r 2 1 12 | sort -n))
Occasionally it creates exactly the same numbers. Is there some fundamental error in my code or am I expecting too much of jot?
Alan B <[email protected]d> wrote:
I've been experimenting with some shell scripting recently. I'm using the
following line of code to create 2 unique random numbers in range 1 to 12
and sort them into ascending numerical order:
numbers=($(jot -r 2 1 12 | sort -n))
Occasionally it creates exactly the same numbers. Is there some fundamental >> error in my code or am I expecting too much of jot?
Isn't that to be expected? It's effectively rolling two 12-sided dice for you. When you do that, sometimes you'll roll a double. Why would you
expect them to be always different?
I've been experimenting with some shell scripting recently. I'm using the following line of code to create 2 unique random numbers in range 1 to 12
and sort them into ascending numerical order:
numbers=($(jot -r 2 1 12 | sort -n))
Occasionally it creates exactly the same numbers. Is there some fundamental error in my code or am I expecting too much of jot?
Of course! I’m now working on a different solution using the RANDOM function plus a test to see if the number has already been generated using
a checklist …. Unless you know better ;-)
I've been experimenting with some shell scripting recently. I'm using the following line of code to create 2 unique random numbers in range 1 to 12
and sort them into ascending numerical order:
numbers=($(jot -r 2 1 12 | sort -n))
Occasionally it creates exactly the same numbers. Is there some fundamental error in my code or am I expecting too much of jot?
Alan B <[email protected]d> wrote:
Of course! I’m now working on a different solution using the RANDOM
function plus a test to see if the number has already been generated using >> a checklist …. Unless you know better ;-)
One way would be to make a list of numbers from 1 to 12, put them in a
random order, and then select the first two. On Linux:
$ seq 12 | shuf | head -2
does it, printing one number per line. If you want them on the same line:
$ seq 12 | shuf | head -2 | paste - -s -d ' '
Of course! I’m now working on a different solution using the RANDOM >function plus a test to see if the number has already been generated using
a checklist. Unless you know better ;-)
In article <tsd5p7$24kvk$[email protected]>,
Alan B <[email protected]d> wrote:
Of course! I’m now working on a different solution using the RANDOM
function plus a test to see if the number has already been generated using >> a checklist. Unless you know better ;-)
What is it you are trying to achieve?
Alan B <[email protected]d> wrote:
Of course! I’m now working on a different solution using the RANDOM
function plus a test to see if the number has already been generated using >> a checklist …. Unless you know better ;-)
One way would be to make a list of numbers from 1 to 12, put them in a
random order, and then select the first two. On Linux:
$ seq 12 | shuf | head -2
does it, printing one number per line. If you want them on the same line:
$ seq 12 | shuf | head -2 | paste - -s -d ' '
| Sysop: | Keyop |
|---|---|
| Location: | Huddersfield, West Yorkshire, UK |
| Users: | 715 |
| Nodes: | 16 (2 / 14) |
| Uptime: | 150:52:26 |
| Calls: | 12,091 |
| Calls today: | 4 |
| Files: | 15,000 |
| Messages: | 6,517,598 |