# How exactly does the rand() function work

Based on my testing it seems like the rand() function returns a guaranteed set of pseudo-random numbers seeded by the optional 'value' parameter.

For example, if a create a card with a beastmode, the first time a beastmode, calls the rand() function (with no parameters) it will return a value of ~0.69.

The second time the rand() function is called (with no parameters) it will return one of two values...

1) if it is being called/referenced in the same beastmode, or another beastmode, but on the same row of data, the identical value of ~0.69 will be returned... again and again.

2) if it is being called by a different row of data, the next value in the pseudo-random sequence will be returned... in this case ~0.31.

Refreshing the page always returns the same numbers in the same order as listed above. Making a copy of the card returns the same results. Putting the same beastmode formulas into a view returns the same results.

Now if we decide to pass a value into the optional parameter, we will get a different pseudo-random sequence. For example, rand(1) always starts with the sequence ~0.16, ~0.09 and rand(2) always starts with the sequence ~0.52, ~0.58.

This means if you want to use 2 different random numbers within the same row of data in domo you need to call rand() with two different values passed in as the parameter.

Just looking for someone to verify that my understanding of this is correct. I'd check the documentation but first they'd need to create some... =/ and out of curiosity - does anyone else see their instance return the same sequences?

Tagged:

• Indiana 🥷

You’re correct that it’ll return the same number from what I’ve seen in the past. If you want it more randomized for each row you’d need to run the random function within an ETL

And if you want it more randomized within each row you would be better seeding it with the `current_time() `function for the first call, the `current_time() + interval 1 day` for the second call, and so on.