0% found this document useful (1 vote)
450 views1 page

Random Number Generator

This Java program generates random numbers between 0 and 65535. It prompts the user to enter the number of random numbers to generate. It then prints out that number of randomly generated numbers and stores them in an array.

Uploaded by

deianira
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
450 views1 page

Random Number Generator

This Java program generates random numbers between 0 and 65535. It prompts the user to enter the number of random numbers to generate. It then prints out that number of randomly generated numbers and stores them in an array.

Uploaded by

deianira
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Random Numbers Generator

/* This program generates random numbers between 0 and 65535.*/

import java.util.Random;
import java.io.*;

public class RandomNumbersGenerator {


static int p;
public static void main (String[] args) {
read_keyboard();
RandomNumbersGenerator generator=new RandomNumbersGenerator();
}
public static void read_keyboard(){
BufferedReader keyboard;

try{

keyboard=new BufferedReader(new InputStreamReader(System.in),1);

System.out.println("how many random numbers you want to generate:");


String s=keyboard.readLine();
p=Integer.parseInt(s);
System.out.println("It will be generated "+p+" "+"random numbers between 0 and
65535 ");
}catch(IOException e){
System.out.println("error while reading from keyboard.Sorry...");

}
catch(NumberFormatException e1){System.out.println("Oh,for Heaven's sake!Give me
a number!");
}

}
public RandomNumbersGenerator() {
Random random_generator=new Random();

int[] random_numbers_array=new int[p];


for(int counter=0;counter<p;counter++) {
random_numbers_array[counter]=(int)
(((random_generator.nextDouble()*25173)+13849)%65536);
System.out.println(random_numbers_array[counter]);
}
}
}

You might also like