Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Random generation of id

  1. #1
    Junior Member
    Join Date
    Jul 2014
    Location
    chennai
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Random generation of id

    Hi

    i want to do a Registration page on some website. i connected to mysql and creating some id like 1 and 2 like this , but i don't want like this. i want to generate v21001 and v21002 to generate on every registration.

    Please give me rply if anybody know the answer means.

    thank you


  2. #2
    Junior Member codepoet's Avatar
    Join Date
    Jul 2014
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Random generation of id

    you could append a character to a Math.floor((Math.random() * [any number]) + [10000]);

    explanation:
    the 10000 will make sure that the number is always 5 digits.

    ex:
    Math.floor((Math.random() * 2323) + 10000);

    Happy coding!

    --- Update ---

    its better if you put the same number of digits to [any number], like if you want 5 digits you can do Math.floor((Math.random() * 12345) + 10000);

Similar Threads

  1. [SOLVED] Random maths operator generation
    By dk87 in forum What's Wrong With My Code?
    Replies: 11
    Last Post: April 8th, 2013, 06:11 AM
  2. How exactly does random block generation work in 2D/3D worlds?
    By vividMario52 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 24th, 2013, 04:27 PM