Results 1 to 2 of 2
  1. #1
    toasty is offline Member
    Join Date
    Sep 2009
    Posts
    1
    Rep Power
    0

    Default Random number generation

    I need to figure out how to code a button that will generate a random 16 digit number every time I push it. I can't find any info on this anywhere.. Any help is appreciated. Thanks.

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    So a random number from
    0 to 8999999999999999 (8 + 15 9's) plus 1000000000000000 (1 + 15 0's)
    will give you what you want, right?

    So, check out the Random class and it's nextLong() method. Then, before adding 1000000000000000 (actually , make sure that the returned long is smaller than 8999999999999999 (8 + 15 9's) and at least 0 (although you could simply take the abs value and not have to worry about checking for negativity) if not use nextLong again.
    Last edited by masijade; 09-30-2009 at 11:46 AM.

Similar Threads

  1. Generating a random number
    By oridov in forum New To Java
    Replies: 2
    Last Post: 11-29-2008, 05:12 PM
  2. Random number generater
    By kickflipper1087 in forum New To Java
    Replies: 6
    Last Post: 10-21-2008, 10:19 PM
  3. Random number help
    By jgonzalez14 in forum New To Java
    Replies: 5
    Last Post: 09-16-2008, 09:13 AM
  4. Random number
    By jithan in forum Advanced Java
    Replies: 1
    Last Post: 06-13-2008, 01:42 PM
  5. random generation
    By carlos123 in forum New To Java
    Replies: 10
    Last Post: 01-09-2008, 03:43 AM

Posting Permissions

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