Hey everyone, just started using Retool and absolutely love it. Have been able to build some amazing SQL tables and buttons etc to help with our business and so far really impressed.
I am stuck on the next project I am trying to create with something that will probably be very simple for most of you retool experts.
Basically I want to provide 3 inputs - Minimum, Maximum & Total
I would like to fill a table with (Total) random values between the (Minimum) and (Maximum)
So for example 100 rows of random numbers between 1 and 5000.
I think you just need to put some min/max values into
Math.random() * (max - min) + min;
There's some deep Stack Overflow discussions about optimizing the randomness and ensuring only integer values are returned, but I think you could just loop this 100 times to insert records into your DB
Thanks for replying Pyrrho! I did find similar code online, the problem I have is I cant work out how I can populate a table with this data? Do I use a transformer or just a JS snippet of code and how do I get it to populate the table? Sorry if this sounds so basic!
Then you would tie the output to the query which would write everything to your DB. You'd probably want to do more than just return an array of integers for this.
Another way would be to build this out as a Retool Workflow instead of an App.
There you could build the same dataset and then send it through a loop node to write values to your DB based on the dataset:
If you haven't yet, be sure to click the Run button on the query rather than just the Preview button. If you see output data in the query but the table says No Data this is most likely what is happening.
If so, it'd just be a matter of running the queries on page load or having a button that refreshes the table data (runs the javascript).
ETA:
Instead of just pushing numbers back to the array, push the values to an object (code line 6):
I must be doing something wrong! The table says 100 results, the code is the same as yours but its not displaying anything? What have I done or need to do?