Random Number Generator
Options
brian
Administrator
ADMIN
Generate a random number with this snippet, using a Lambda function.
- Snippet: https://www.xano.com/snippet/kNYFQdMy
- Video walk-through: https://www.loom.com/share/ab0e0e6d9a1e425fa22559f7e1b582bf
- Instructions: how to add a snippet
It features:
- GET /random_number: an API that accepts two inputs, min (an integer) and max (an integer) and returns a random integer between or equal to them.
You can use this snippet to learn how to:
- Use Lambda functions
- Use Math functions
Feel free to add suggestions, requests, or questions in the comments!
Comments
-
How can I generate random numbers with 0(s) in the begging? (let´s say I need 3-digit numbers from 000-999)
Thank you -
Hey @pkramar! I build something that could possibly work for you.
- Used the Generate Random Number function
- Set the min integer to 0 and the max to 999
- Added a conditional statement to check if the number was between 10 and 99
- If yes, I used the concat filter to add a 0 in front of the random number
- Added another conditional statement to check if the number was between less than 10
- If yes, I used the concat filter to add 00 in front of the random number
- Returned the random number
The potential issue that I see with this is that the concat filter turns the type number into the type text. So on random numbers that are being updated by the concat filter, turn to the type text.
Check out the
to_int
, if you need to turn the random number into an integer.
Let me know if this works for you. 😊 - Used the Generate Random Number function
Categories
- All Categories
- 53 ? Announcements
- 47 ? Releases
- 37 ? Welcome
- 983 ? Help! I'm a Noob
- 125 ? No-Code Front-Ends
- 633 ? Working with APIs
- 439 ? Transforming data
- 126 ? Connect Xano to ...
- 50 ?? Find an Expert
- 348 ❓Other questions
- 35 ? Security
- 22 ✂️ Snippets
- 19 ? Showcase
- 7 ?️ Xano Chatter
- 62 ? Video Tutorials
- 171 ? Request a feature
- 229 ? Report a Bug
- 19 ? Templates & Extensions
- 7 ? Feedback