Talk:Generate random numbers without repeating a value

Why not use shuffle

Knuth_shuffle

That's what I'd do in practice though the task is to generate the random numbers individually without repetition so that's what I've done. --PureFox (talk) 17:58, 24 August 2021 (UTC)
There are times you have to read between the lines: in this case what was asked for is almost certainly not what was actually wanted. I placed more emphasis on the "Try your best not to make the process take too long at runtime." part, which to me means not generating/testing/discarding potentially thousands of numbers, and instinctively used shuffle() as you suggest, more in line with the Julia, Raku, and REXX entries. --Pete Lomax (talk) 03:06, 26 August 2021 (UTC)
Well, if that's what the author intended, the task description seems a very long-winded way of saying: "create a list of the first 20 positive integers and randomly shuffle them". Anyway, as that seems to be the consensus view, I've added alternative implementations to my own efforts. --PureFox (talk) 08:53, 26 August 2021 (UTC)
Of course the other thing not specified in the task is what happens if you call the function 21 times, or after generating some permute of 1..20 (that is, if calling individually) how you would then start on a permute of say 1..10, or even interleave them. Using shuffle sidesteps all such issues. --Pete Lomax (talk) 01:30, 27 August 2021 (UTC)
Return to "Generate random numbers without repeating a value" page.