Search code examples
javautility

Java inbuilt utility for generating a random sequence of numbers


Is there any inbuilt utility in java that I can use to genrate random numbers ? The format is xxxxxxxxxx and max limit of 10 numbers.


Solution

  • You can use Math.random() which returns number between 0 to 1. You can multiply any 1000000000 for getting 10 digit random number.

    Math.floor(Math.random()*100000000000)
    

    Check out Math , specially Math.random() and Math.floor() for rounding off