RandBetween() generating the same number for every row in a virtual column?

Hi all, I’m trying to use randbetween(1,9999) to create a random sort order for a view in my app as in this discussion:

The problem is that when I create the virtual column and put =randbetween(1,9999) in the formulas, and look through all the records, they all get assigned the same random number. If I resync the app, the number gets regenerated, but still the same for all records. Any thoughts on how to fix? Appreciate it.

Solved Solved
0 3 478
1 ACCEPTED SOLUTION

Steve
Platinum 5
Platinum 5

Yeah, I’ve noticed this before myself. I suspect it has to do with the way RANDBETWEEN() is implemented. Try this instead:

RANDBETWEEN([_ROWNUMBER], ([_ROWNUMBER] + 9999))

An alternative would be to use UNIQUEID() rather than RANDBETWEEN(). It wouldn’t be a number, but it’ll produce a random sort.

For the technically inclined, I suspect the underlying random number generator is being seeded with the current time for each RANDBETWEEN() invocation. In a case like this, all of those seeds would be the same time, so the same “random” number would be generated for each.

View solution in original post

3 REPLIES 3
Top Labels in this Space