SOLVED

Randarray doesn't return unique integers!

Copper Contributor

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,

 

2 Replies
best response confirmed by Raymond_Latour (Copper Contributor)
Solution

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

 

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.

1 best response

Accepted Solutions
best response confirmed by Raymond_Latour (Copper Contributor)
Solution

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

 

View solution in original post