Results 1 to 11 of 11
  1. #1
    carlos123 is offline Member
    Join Date
    Nov 2007
    Posts
    38
    Rep Power
    0

    Smile random 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.

  2. #2
    roots's Avatar
    roots is offline Moderator
    Join Date
    Jan 2008
    Location
    Dallas
    Posts
    293
    Rep Power
    7

    Default

    For generation .. javarng - Google Code
    and Follow wikipedia as well ..
    under 20 is not a problem just mod by 20..
    dont worry newbie, we got you covered.

  3. #3
    carlos123 is offline Member
    Join Date
    Nov 2007
    Posts
    38
    Rep Power
    0

    Default

    i forgot to mention i cannot use the java.random class. LOL

  4. #4
    roots's Avatar
    roots is offline Moderator
    Join Date
    Jan 2008
    Location
    Dallas
    Posts
    293
    Rep Power
    7

    Default

    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 ..
    dont worry newbie, we got you covered.

  5. #5
    carlos123 is offline Member
    Join Date
    Nov 2007
    Posts
    38
    Rep Power
    0

    Default

    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.

  6. #6
    roots's Avatar
    roots is offline Moderator
    Join Date
    Jan 2008
    Location
    Dallas
    Posts
    293
    Rep Power
    7

    Default

    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 .. :)
    dont worry newbie, we got you covered.

  7. #7
    carlos123 is offline Member
    Join Date
    Nov 2007
    Posts
    38
    Rep Power
    0

    Default

    im sorry, im new to java , i dont know what nanotime is

  8. #8
    roots's Avatar
    roots is offline Moderator
    Join Date
    Jan 2008
    Location
    Dallas
    Posts
    293
    Rep Power
    7

    Default

    System.nanoTime() gives time in nanoseconds ...
    dont worry newbie, we got you covered.

  9. #9
    carlos123 is offline Member
    Join Date
    Nov 2007
    Posts
    38
    Rep Power
    0

    Default

    whats an existing random number generator algorithm

  10. #10
    carlos123 is offline Member
    Join Date
    Nov 2007
    Posts
    38
    Rep Power
    0

    Default

    and how would i bound nano seconds to 20

  11. #11
    carlos123 is offline Member
    Join Date
    Nov 2007
    Posts
    38
    Rep Power
    0

    Default

    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]);
    }

Similar Threads

  1. EJB generation with xdoclet tags
    By gugas in forum Enterprise JavaBeans (EJB)
    Replies: 0
    Last Post: 02-18-2008, 01:07 PM
  2. random numbers without random class`
    By carlos123 in forum New To Java
    Replies: 4
    Last Post: 01-17-2008, 10:44 PM
  3. random numbers
    By carlos123 in forum New To Java
    Replies: 1
    Last Post: 12-22-2007, 02:56 AM
  4. String generation
    By codingisfun22 in forum Advanced Java
    Replies: 3
    Last Post: 12-03-2007, 05:43 AM
  5. Math.Random
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-23-2007, 02:09 PM

Posting Permissions

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