50 likes | 236 Vues
Random Numbers. Random Numbers. Are a series of numbers that have no pattern to them Ex) 7, 31, 4, 9, 8, 99… Random Numbers are used in… - Computer Games - Lotteries(6-49) - Screen Savers. Math.random. Part of the java.lang package
E N D
Random Numbers • Are a series of numbers that have no pattern to them Ex) 7, 31, 4, 9, 8, 99… • Random Numbers are used in… - Computer Games - Lotteries(6-49) - Screen Savers
Math.random • Part of the java.lang package • The random() methods generates a double between 0 and 1.0. For example,double rNum; rNum = Math.random(); • A random integer in a range is generated by using the expression:(highNum – lowNum + 1) * Math.random() + lowNum
Examples • To generate Random Numbers between 20 and 100 rNum= (100 – 20+1) * Math.random() + 20; • To generate Random Numbers between 10 and 50 rNum= (50 – 10+1) * Math.random() + 10;