I'm using AWK to generate values between 1 - 6 which need to come out in random order. I have managed to sort out the logic for the creation of the right range of numbers but am struggling with reading those in to an array to prevent duplicate numbers being output. Currently my code has this;-
BEGIN{
FS=""
}{
for (i=1; i<=6; ++i) {
v=(int (rand()*6)+1
print v }
This currently outputs six numbers but shows duplicates 2, 2, 6, 1, 4, 2.
What I need the output to be is something like 1, 4, 2, 5, 6, 3
Can anyone please help with the array side of this for my AWK program?
Many thanks
Asked by Jonathan B
(59 rep)
May 6, 2021, 01:21 PM
Last activity: May 2, 2025, 11:14 AM
Last activity: May 2, 2025, 11:14 AM