Forum Discussion

Raymond_Latour's avatar
Raymond_Latour
Copper Contributor
Jan 03, 2024
Solved

Randarray doesn't return unique integers!

Is there a way to return unique integers in an array? I was sure RANDARRAY(8,1,1,8,1) returned unique integers in each row for a while.  I can't duplicate it anymore. Thanks,  
  • HansVogelaar's avatar
    Jan 03, 2024

    RANDARRAY does not necessarily return unique values.

    Take =RANDARRAY(8, 1, 1, 4, 1)

    If you generate 8 integers between 1 and 4, they simply cannot be unique.

    To shuffle the numbers 1 to 8:

     

    =SORTBY(SEQUENCE(8), RANDARRAY(8))

     

Resources