# random numbers without using java funtions

• 11-15-2007, 04:03 AM
carlos123
random numbers without using java funtions
i need a formula to generate 100 random numbers 1-20

any suggestions?

remember, no functions

thanks.
• 11-15-2007, 04:49 AM
hardwired
int n = (int)(1 + 20*Math.random());
• 11-15-2007, 04:50 AM
carlos123
we cannot use the Math.random function
• 11-15-2007, 04:53 AM
carlos123
this is some code it - Each number needs to be generated.
Each number should be generated at least 300 times of the 10,000.

Code:

```public class Random_Gen {     int min;                    //minimum number that can be generated.         int max;                    //maximum number that can be generated.     int value;         public Random_Gen(int n, int m)         {         max = m;                //code goes in this class             min = n;                   }                 public int getRandom()         {                           return value;                     } } public static void main(String[] args)         {             int min = 1;                // smallest number that can be generated             int max = 20;                // largest number that can be generated             Random_Gen  rg = new Random_Gen(min, max);             int num;             int[] frequency = new int[max];                                     for (int x = 0; x < 10000; x++)             {               num = rg.getRandom();                             System.out.println(num);                             for (int index = 0; index < max; index ++)    //determines frequency                   {                   if (num == index + 1)                     frequency[index]++;                   }             }                                       for (int index = 0; index < max; index ++)    // displays frequency             {                 System.out.println(""+(index+1) + " = " + frequency[index]);             }   }```
• 11-15-2007, 05:29 AM
hardwired
Can you use the java.util.Random class?
Edit: random numbers without using java funtions
aha - no java. Check the next method in the Random class for some clues.
• 11-15-2007, 11:45 PM
carlos123
i dont understand
• 11-16-2007, 12:01 AM
lk9865
Quote:

Originally Posted by hardwired
Can you use the java.util.Random class?
Edit: random numbers without using java funtions
aha - no java. Check the next method in the Random class for some clues.

carlos,
just like hardwired said there is another java class called Random you can upload before your programs you try something like this
Code:

```java.util.Random; public class RandomProject{ public staid void main(strings[] args){ Random generator = new Random(); //give a object name for the class for(int i=0; i<=100; i++){ int randomNumbers = generator.nextInt(20);//will generate numbers from1-20 System.out.println(randomNumbers); } } }```
there you go you have now generated 100 random numbers between 1 and 20 hope this helps
• 11-16-2007, 04:39 AM
carlos123
we cannot use any java functions
• 11-16-2007, 11:13 AM
JavaBean
Quote:

we cannot use any java functions
Then try searching "generating random numbers" on Google and try to implement your own random number generator.