# Thread: random numbers without using java funtions

1. Member Join Date
Nov 2007
Posts
38
Rep Power
0

## random numbers without using java funtions

i need a formula to generate 100 random numbers 1-20

any suggestions?

remember, no functions

thanks.  Reply With Quote

2. ## int n = (int)(1 + 20*Math.random());  Reply With Quote

3. Member Join Date
Nov 2007
Posts
38
Rep Power
0

## we cannot use the Math.random function  Reply With Quote

4. Member Join Date
Nov 2007
Posts
38
Rep Power
0

## this is some code it - Each number needs to be generated.
Each number should be generated at least 300 times of the 10,000.

Java 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]);
}
}```  Reply With Quote

5. ## 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.
Last edited by hardwired; 11-15-2007 at 05:01 AM. Reason: read the title  Reply With Quote

6. Member Join Date
Nov 2007
Posts
38
Rep Power
0

## i dont understand  Reply With Quote

7. Member Join Date
Nov 2007
Posts
8
Rep Power
0

##  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
Java 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  Reply With Quote

8. Member Join Date
Nov 2007
Posts
38
Rep Power
0

## we cannot use any java functions  Reply With Quote

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

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•