dcsimg
LinkedIn
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
May 18, 2021

How to Generate Random Integers in Java

Generating random integer values in Java is pretty straightforward. In this programming tutorial, we will be using the int method of the Random class from java.util.Random to achieve our goals.

*/

import java.util.Random;

public class RandomIntGenerator {

    public static void main(String[] args)
	{
		RandomIntGenerator randomIntGenerator = new RandomIntGenerator();
		randomIntGenerator.proceed();
	}

	private void proceed()
	{
		Random random = new Random();
		random.ints(100,200).forEach(System.out::println);
	}
}

/*

The output is not complete. It is just a generator and the values are unlimited. Press Ctrl+C to stop the application.

Output:

$java RandomIntGenerator
153
100
133
141
148
121
132
133
136
188
MS Sridhar
 
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date