1 / 4

Random Numbers

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

elaina
Download Presentation

Random Numbers

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Random Numbers

  2. 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

  3. 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

  4. 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;

More Related