Home > database >  Google Sheet Apps Script Random Number in 5 Rows no repeat
Google Sheet Apps Script Random Number in 5 Rows no repeat

Time:12-30

I need help with my Google Sheet. I want to create 1 row with 5 columns and they should be filled with random numbers between 1 and 15 (example) with no repeat. I`ve tried it already with the randbetween function.

I formatted the cells with =RANDARRAY(1;5), to give me an output of 1 row and 5 columns but how can I add here the randbetween function with no repeating the numbers from 1-15? And full numbers.

Thanks.

CodePudding user response:

This should work for you:

=TRANSPOSE(SORTN(SEQUENCE(15);5;0;RANDARRAY(15);1))

In plain English, this reads as follows:

"Create an ordered vertical list of the sequence of numbers from 1 to 15, sort them according to a vertical random array of 15 numbers, return the top 5 results and then transpose the vertical list to a horizontal one."

The 0 tells SORTN how to process ties; but since there won't be any, it's just a filler parameter here.

  • Related