ok guys, i need to generate 10,000 random numbers less then 20, i want my program to take the seconds from the clock, divide it by 3, and then put it through a formula to then create 10,000 psuedo-random numbers, under 20, any help guys. thanks.

Printable View

- 01-08-2008, 08:22 AMcarlos123random generation
ok guys, i need to generate 10,000 random numbers less then 20, i want my program to take the seconds from the clock, divide it by 3, and then put it through a formula to then create 10,000 psuedo-random numbers, under 20, any help guys. thanks.

- 01-08-2008, 08:31 AMroots
For generation .. javarng - Google Code

and Follow wikipedia as well ..

under 20 is not a problem just mod by 20.. - 01-08-2008, 08:52 AMcarlos123
i forgot to mention i cannot use the java.random class. LOL

- 01-08-2008, 08:55 AMroots
Exactly .. Above link is similar implementation .. Review how they have done and write yours ..

Art of Computer Programming by Donald E. Knuth is a good book to have for this .. - 01-08-2008, 09:03 AMcarlos123
im not suppose to use those algorithms, its just basicly, i take the seconds, and divide it by 3, and put it through a formula 10,000 times, and it should be kind of random, like it doesnt have to be completly random, its just a test on how random we can make a program without using those random elements. comprende? any suggestions on the formula would help.

- 01-08-2008, 09:15 AMroots
nanoTime() when bounded by limit of 20 itself gives pretty different results. You can mess it up stretching it up with arithmetic operation of your choice. nada . I am not talking about taking the algorithm .. you need to write yours .. But you will get basic idea from existing random number generator algorithm .. :)

- 01-08-2008, 09:19 AMcarlos123
im sorry, im new to java , i dont know what nanotime is

- 01-08-2008, 09:24 AMroots
System.nanoTime() gives time in nanoseconds ...

- 01-08-2008, 09:25 AMcarlos123
whats an existing random number generator algorithm

- 01-08-2008, 09:26 AMcarlos123
and how would i bound nano seconds to 20

- 01-09-2008, 04:43 AMcarlos123
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]);

}