import java.io.*;
import java.util.*; class randomgen { public static void main(String args[])throws IOException { int i; int r[]=new int[10]; int arr1[]=new int[10]; BufferedReader b=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Random number generated using in built function "); Random randomGenerator = new Random(); for (i = 0; i < 10; i++) { int randomInt = randomGenerator.nextInt(100); arr1[i]=randomInt; System.out.print(randomInt+" "); } System.out.println("\nRandom number generated using linear congruential method "); System.out.println("Enter the values of X0,a,c and m \n"); int x=Integer.parseInt(b.readLine()); int a=Integer.parseInt(b.readLine()); int c=Integer.parseInt(b.readLine()); int m=Integer.parseInt(b.readLine()); for(i=0;i<10;i++) { int rand=((a*x+c)%m); r[i]=rand; System.out.print(r[i]+" "); x=rand; } } } /*output Z:\>javac randomgen.java Z:\>java randomgen Random number generated using in built function 50 40 91 55 65 58 68 35 49 66 Random number generated using linear congruential method Enter the values of X0,a,c and m 1 13 0 100 13 69 97 61 93 9 17 21 73 49 */
0 comments :
New comments are not allowed.