How to generate 8 digit random number in Java

1 Answer

0 votes
package javaapplication1;

import java.util.Random;

public class Example {
    
    public static final int N = 20;
    
    public static void main(String[] args) {
               
        Random rand = new Random(); 

        for (int i = 0; i < N; i++) 
            System.out.println(rand.nextInt(90000000) + 10000000);

        // min = 0 + 10000000 
        // max = 9000000 - 1 + 1000000 = 9999999 
    }
}
 
/*
run:
  
12603059
45573583
54026094
84590083
89817141
41364953
55022963
43230811
80919434
24757791
92697139
91618140
16203168
15369342
32149297
56819032
29291114
58589485
29431089
70335807
  
*/

 



answered Apr 28, 2016 by avibootz

Related questions

1 answer 187 views
1 answer 205 views
1 answer 212 views
1 answer 703 views
1 answer 195 views
195 views asked Apr 27, 2016 by avibootz
1 answer 261 views
1 answer 247 views
247 views asked Apr 26, 2016 by avibootz
...