Search code examples
google-sheetsrandomnumbersgeneratorpermutation

How do I make a random permutation function in Google Sheets


I need to generate a function on google sheets that randomly generates 8 numbers within the range of 1:8. It needs to be a permutation, so none of the 8 numbers should repeat. I am able to do this in R, but my advisor is requesting that I do it in google sheets. If you need any additional information to make this work please let me know!

I have tried using a random array function and restricted the range to 1-8 but it will generate the same number multiple times.


Solution

  • You can create a SEQUENCE of the 8 numbers from 1 to 8, and then sort them by a random sequence of 8 numbers (with RANDARRAY). This way, you'll always see the same 8 numbers but sorted differently each time:

    =SORT(SEQUENCE(8),RANDARRAY(8),1)