Created
February 11, 2011 13:53
-
-
Save rafaelrinaldi/822364 to your computer and use it in GitHub Desktop.
Get a random number between any two numbers.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package tea.number | |
{ | |
/** | |
* Get a random number between any two numbers. | |
* | |
* http://help.adobe.com/cs_CZ/AS2LCR/Flash_10.0/help.html?content=00001226.html | |
* | |
* @param p_start The first number. | |
* @param p_end The last number. | |
* | |
* @return A random number between first and second arguments. | |
* | |
* @example | |
* <pre> | |
* import tea.number.randRange; | |
* | |
* var num : Number = randRange(0, 5); | |
* trace("My random number between 0 and 5, is", num); | |
* </pre> | |
* | |
* @see tea.number | |
* | |
* */ | |
public function randRange( p_start : Number, p_end : Number, p_rounded : Boolean = true ) : Number | |
{ | |
const range : Number = p_start + (Math.random() * (p_end - p_start)); | |
if(p_rounded) return Math.round(range); | |
return range; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment