Random sorting

It should be plenty possible to implement @Daniel_Steigerwald’s pseudorandom number generator directly in FQL where you would provide access to a UDF Create function but not the standard one. Daniel’s links are rather esoteric, but the code there is an easy example of what can be done. The seed value can be stored in the data for the function, and interestingly enough, a function can update itself!

This implements the code above in FQL for a UDF named “srng”

Query(
  Lambda(
    [],
    Let(
      {
        seed: Select(["data", "seed"], Get(Function("srng")), 1),
        nextSeed: Modulo(
          Add(Multiply(1839567234, Var("seed")), 972348567),
          8239451023
        ),
        functionUpdate: Update(Function("srng"), {
          data: { seed: Var("nextSeed") }
        })
      },
      Var("nextSeed")
    )
  )
)
2 Likes