functions expression rules

Certified Senior Developer

for example, I am having 10 questions in my DB  for that each question has a unique question id

If I enter 5 then 5 question id  should be come randomly help me out on this 

  Discussion posts and replies are publicly visible

Parents Reply
  • Hi there,

    This can be another approach. You generate a list of incremental random values, all unique. And then use that array to index from the list of available questions. 

    Below is the code for the same. 

    a!localVariables(
      local!questionsData,
      local!array: 1 + tointeger(rand(5) * (1000 - 1)),
      local!sortedArray: rule!BAM_utils_sortArray(
        arrayValues_any: local!array,
        ascending_bool: true
      ),
      local!randomIndex: a!flatten(
        a!forEach(
          items: local!sortedArray,
          expression: wherecontains(fv!item, local!array)
        )
      ),
      index(
        local!questionsData,
        local!randomIndex,
        {}
      )
    )

    In local!array, I am trying to generate the values in a specific range. The parameter of rand() function will give us 5 values. You can change it to n.

Children
No Data