The random() function in p5.js is used to return a random floating point number between ranges given as the parameter.
Parameters: This function accepts three parameters as mentioned above and described below:
- Min: This is the lower bound of the random number which is going to be created. This is an inclusive number with the created random number.
- Max: This is the upper bound of the random number which is going to be created. This is an exclusive number with the created random number.
- Array: This is an array of some elements from which any random number is returned.
Return Value: It returns the random number.
Below programs illustrate the random() function in p5.js:
Example 1: This example uses random() function to return a random floating point number between the given range.
Note: In the above code, in variable “C” only one parameter is passed then it returns a random number from lower bound 0 to upper bound of that number.
Example 2: This example uses random() function to return a random floating point number between the given range.
- Collect.js | random() function
- Underscore.js _.random() Function
- Program to generate random string in PHP
- How to generate a random, unique, alphanumeric string in PHP
- Generating Random String Using PHP
- PHP program to Generate the random number in the given range (min, max)
- How to get random value out of an array in PHP?
- Lodash _.random() Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.