Results 1 to 2 of 2

Thread: Random number

  1. #1
    jithan is offline Member
    Join Date
    Jun 2008
    Posts
    39
    Rep Power
    0

    Default Random number

    hello friends,
    i want to generate a 32 digit random number...........pls help me....... its very urgent...........

    Thanks in advance.........

  2. #2
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    If i were to do that( in integer),

    Since the maximum positive integer in java is (2 power 31)-1,

    i may use a next random number of 9 power 15,
    Java Code:
    int val = new Random().nextInt(9 power 15);
    filter all those value less than 1 power 15 except the greater values.....(to have a 16 digit value)

    store in a temp variable,
    Same procedure again, store in another variable,

    Convert the two integer values into String, then use the concat method....(I should show first the output to insure that my algorithm is right)

    In Long, you can use directly the nextLong(Long val) to generate values.... by filtering the generated value except the requirement,
    You can now have your 32 digit random digit number....
    Last edited by sukatoa; 06-13-2008 at 01:47 PM.
    freedom exists in the world of ideas

Similar Threads

  1. random numbers without random class`
    By carlos123 in forum New To Java
    Replies: 4
    Last Post: 01-17-2008, 10:44 PM
  2. Random Generator
    By padutch2 in forum New To Java
    Replies: 1
    Last Post: 12-03-2007, 06:43 PM
  3. Generate a random number
    By romina in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 05:23 AM
  4. How to generate random number in java
    By fernando in forum New To Java
    Replies: 1
    Last Post: 08-01-2007, 07:32 PM
  5. Random Image on Refresh (FROM Folder not set number)
    By QuinnMal in forum Java Servlet
    Replies: 1
    Last Post: 07-06-2007, 07:27 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
  •