Random number generator (I'm new to java)

Discussion in 'Java' started by vishnu_alapati, Apr 19, 2006.

  1. vishnu_alapati

    vishnu_alapati New Member

    Joined:
    Apr 19, 2006
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    hai,

    I need to generate a 12-digit random per application such that the number generated should not be generated until the application is run for 4294967296 times.
    I need an approach to store the generated number in a file and modify the file after the file length reaches 4294967296.
    So please help me out ......
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Can you explain what you mean by application running 4294967296 times? Do you mean a loop?
     
  3. vishnu_alapati

    vishnu_alapati New Member

    Joined:
    Apr 19, 2006
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    what I mean is, the random once number generated should not be generated until 4294967296 other random numbers are generated, So to check for this condition I need to store the generated numbers in a file or database and modify them after 4294947296 numbers are generated.
     
  4. coderzone

    coderzone Super Moderator

    Joined:
    Jul 25, 2004
    Messages:
    736
    Likes Received:
    38
    Trophy Points:
    28
    Code:
      // random number between 0 AND 10
      import java.util.Random;
      Random r = new Random();
      int randInt = r.nextInt(10);
    Isnt this looping 4294967296 times give you what you are looking for. Now using the FileReader and FileWriter classes will help you write them to file and read from there.
     
  5. angelina7744

    angelina7744 New Member

    Joined:
    Dec 13, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Hi i need to generate a random number (between 0 and 2) in an array[15][3]..the first column should be from 1 to 15 and thats k ive done that but the 2nd and 3rd column should generate a random number of 0 to 2 but its not working...ive done the following till now:
    Code:
    #include<stdio.h>     /* for printf */
    #include<stdlib.h>   /* for rand*/
    
      void main(void)
     {
      int t, i, num[15][3];
    
      for(t=0; t<15; ++t)
      for(i=0; i<3; ++i)
      num[t][0] = t+0+1;
      
    
      /* now print them out */
      for(t=0; t<15; ++t) {
        for(i=0; i<3; ++i)
        printf("%3d", num[t][0]);
         printf("\n");
    
      }
    } 
    help me plz...
     
    Last edited by a moderator: Dec 14, 2007
  6. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    It looks like you are trying to write the C source code for your Java assignment. You need some break and chill out before you start on writing the code.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice