Uploaded May 2016 | Updated December 2026, 6 hours ago
GitHub repo with examples github.com/SleekPanther/java-math-improved-random
Random numbers are a common part of many programs and games. (Yeah I know they're not truly "random" but pesudorandom numbers are the best computer can do)
There are 2 main ways: Using a static method of the built-in Math class, or creating a Random object & calling methods on that object
➣Math.random()
-The "Math" class is built-in (no need to import) so calling "Math.random()" gives you a double from 0 to 1
-Not very useful on its own, but the result it can be multiplied to give a "range" of number
-"Math.random()*10" gives a range of 10 so 0 through 9.99999
-The upper bound is always excluded so you'd need to add 1 to get an inclusive range
-"(int)(Math.random()*10)" casts the result to an integer
-or replace "(int)" with "Math.round()" or "Math.floor()"
-You can also change the lower bound by adding a number to the end: (int)(Math.random()*10)+10 yields numbers from 10 to 19 (20 is excluded)
int min = 5;
int max = 15;
int range = max - min +1;
-Range must be 1 greater than the range you want since the upper bound will always be excluded
(int)(Math.random()*range ) +min
-This will give you the desired result
-Negative values for min & max still work as long as you still add 1 to the range
-Getting decimals just involves removing the (int) casting
-You might want to round off the numbers to only display a few decimals
➣Random class
-Random generator = new Random();
-Creates a new Random object with reference variable "generator"
-don't forget to "import java.util.Random;"
-You can now use the formula like this:
(int)(generator .nextDouble()*range ) +min
-Unfortunately nextDouble() can't accept parameters so you basically just use it like Math.random()
-generator.nextInt() give you an integer in the range negative 2 billion to positive 2 billion
-But you can also use get an integer in a specific range
-generator.nextInt(5) yields numbers 0 to 4 (5 is excluded)
-The formula can now be used like this
-generator.nextInt(range) + min;
Details on Random docs.oracle.com/javase/7/docs/api/java/util/Random.html
Editor I used (Eclipse) eclipse.org/downloads
GitHub repo with examples github.com/SleekPanther/java-math-improved-random
Random numbers are a common part of many programs and games. (Yeah I know they're not truly "random" but pesudorandom numbers are the best computer can do)
There are 2 main ways: Using a static method of the built-in Math class, or creating a Random object & calling methods on that object
➣Math.random()
-The "Math" class is built-in (no need to import) so calling "Math.random()" gives you a double from 0 to 1
-Not very useful on its own, but the result it can be multiplied to give a "range" of number
-"Math.random()*10" gives a range of 10 so 0 through 9.99999
-The upper bound is always excluded so you'd need to add 1 to get an inclusive range
-"(int)(Math.random()*10)" casts the result to an integer
-or replace "(int)" with "Math.round()" or "Math.floor()"
-You can also change the lower bound by adding a number to the end: (int)(Math.random()*10)+10 yields numbers from 10 to 19 (20 is excluded)
int min = 5;
int max = 15;
int range = max - min +1;
-Range must be 1 greater than the range you want since the upper bound will always be excluded
(int)(Math.random()*range ) +min
-This will give you the desired result
-Negative values for min & max still work as long as you still add 1 to the range
-Getting decimals just involves removing the (int) casting
-You might want to round off the numbers to only display a few decimals
➣Random class
-Random generator = new Random();
-Creates a new Random object with reference variable "generator"
-don't forget to "import java.util.Random;"
-You can now use the formula like this:
(int)(generator .nextDouble()*range ) +min
-Unfortunately nextDouble() can't accept parameters so you basically just use it like Math.random()
-generator.nextInt() give you an integer in the range negative 2 billion to positive 2 billion
-But you can also use get an integer in a specific range
-generator.nextInt(5) yields numbers 0 to 4 (5 is excluded)
-The formula can now be used like this
-generator.nextInt(range) + min;
Details on Random docs.oracle.com/javase/7/docs/api/java/util/Random.html
Editor I used (Eclipse) eclipse.org/downloads





![How to Make a YouTube Video Repeat Forever
Heres how to make a YouTube video auto-repeat until the end of time.
If you want to have a video that you uploaded repeat once it has finished, just put a pause annotation at the end. Make it at short as possible (0:00:00:1) and move it the the VERY end of the timeline.
This somehow cheats YouTube into playing the video over and over again.
If you want to repeat someone elses video, you can create a new playlist for that one video and just click the Autoplay button on the playlist bar.
If you dont have a YouTube account, you can just add repeat after youtube to the video URL. So http://www.youtube.com/[INSERT URL] becomes http://www.youtuberepeat.com[INSERT VIDEO URL]
********************UPDATE*************************
http://youtuberepeat.com/ is now http://listenonrepeat.com/ but it still redirects to the correct site if you type repeat in the URL like I showed
Thanks to Stephen Mclean for giving me this idea http://www.youtube.com/watch?v=mVmblHl3fEQ How to Make a YouTube Video Repeat Forever](https://i.ytimg.com/vi/t-ucXXj3moI/mqdefault.jpg)




