Forum Discussion

Raymond_Latour's avatar
Raymond_Latour
Copper Contributor
Jan 03, 2024

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,

 

  • 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))

     

  • 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))

     

    • Raymond_Latour's avatar
      Raymond_Latour
      Copper Contributor

      Hi Hans.

      I was trying to generate integers between 1 and 8, for and array of 8 x 1.
      I thought it should work.  Obviously not.  Your solution does.

      Thanks again.

Resources