Generate RANDOM and UNIQUE numbers for a specific range

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

Parents
  • 0
    Certified Associate Developer

    here is the recursive approach for getting x amount of unique numbers between a define range

    a!localVariables(
      local!random: ri!min + tointeger(rand() * (ri!max - ri!min)),
      local!arrray: append(ri!array, local!random),
      if(
        length(union(local!arrray, local!arrray)) >= ri!count,
        local!arrray,
        rule!CP_getRandomList(
          min: ri!min,
          max: ri!max,
          count: ri!count,
          array: union(local!arrray, local!arrray)
        )
      )
    )
    // NOTE - count < max - min    
    ,

    more insights ->

     

Reply
  • 0
    Certified Associate Developer

    here is the recursive approach for getting x amount of unique numbers between a define range

    a!localVariables(
      local!random: ri!min + tointeger(rand() * (ri!max - ri!min)),
      local!arrray: append(ri!array, local!random),
      if(
        length(union(local!arrray, local!arrray)) >= ri!count,
        local!arrray,
        rule!CP_getRandomList(
          min: ri!min,
          max: ri!max,
          count: ri!count,
          array: union(local!arrray, local!arrray)
        )
      )
    )
    // NOTE - count < max - min    
    ,

    more insights ->

     

Children
No Data