Hello,
I am trying to randomly sample x amount of rows from a CDT by generating x random numbers in the range 1:length(myCdt). The issue I am getting is that some of these random numbers are repeated.
Is there a way to generate random numbers in a given interval and have them be unique?
Here is what I have so far:
local!randomNumbers:if(
length(local!query)>15, 1+ tointeger(rand(15) * length(local!query)), local!query,
),
Discussion posts and replies are publicly visible
a!localVariable( local!possibleNumbers: difference( 1+enumerate(ri!upper), 1 + enumerate(ri!lower) ), local!count: length(local!possibleNumbers), local!randomIndex: tointeger(local!count*(rand())), if(local!randomIndex =0, local!possibleNumbers[tointeger(local!count*(rand()))], local!possibleNumbers[local!randomIndex] ) )
Your code generates a single random number between two boundaries. A more simple variant is
ri!lower + tointeger(rand() * (ri!upper - ri!lower))
Thanks for the advice, any way this could be used to generated x amount of numbers that are all unique?