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 354
1 ACCEPTED SOLUTION

Steve
Platinum 4
Platinum 4

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

Steve
Platinum 4
Platinum 4

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.

That worked perfectly, thanks.

FYI for anybody else reading, I tried the uniqueID solution as well first, and it always generates the same alphanumeric value for all records…

Wow. I was about to say there’s no way that’s true. But then I tested it myself and confirmed.

Top Labels in this Space