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?
Answers
-
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
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**0 -
It's probably also worth noting you can make the numbers appear more random by seeding it with the result of the current_time() function. This means when you refresh the page at least you will get different results each time...
0 -
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, thecurrent_time() + interval 1 day
for the second call, and so on.0
Categories
- All Categories
- 1.8K Product Ideas
- 1.8K Ideas Exchange
- 1.6K Connect
- 1.2K Connectors
- 300 Workbench
- 6 Cloud Amplifier
- 9 Federated
- 2.9K Transform
- 102 SQL DataFlows
- 626 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 753 Beast Mode
- 61 App Studio
- 41 Variables
- 692 Automate
- 177 Apps
- 456 APIs & Domo Developer
- 49 Workflows
- 10 DomoAI
- 38 Predict
- 16 Jupyter Workspaces
- 22 R & Python Tiles
- 398 Distribute
- 115 Domo Everywhere
- 276 Scheduled Reports
- 7 Software Integrations
- 130 Manage
- 127 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 11 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 110 Community Announcements
- 4.8K Archive