Forum Discussion

User999's avatar
3 years ago

Generate Random Guid (5 digits)


I am looking to generate a simple 5/6 digit random number or string for an ID.  I know I can generate a GUID using ${=java.util.UUID.randomUUID()} in the request but is there a specific way to generate a small number/string?



2 Replies

  • richie's avatar
    Community Hero

    Hey User999 


    you can use the same sort of approach you use to dynamically generate a GUID (e.g. ${=java.util.UUID.randomUUID()}) as to generate a unique number based on the current timestamp or current date, etc., there's also a Math.random() method you can use too.


    I'm on the wrong laptop so I'll check later (my ReadyAPI is on a different laptop) - but my question -->  what's the max field length of the unique numbers you want to generate?


    Also - I think (going from memory here - I've never actually used it) the DataGenerator (DataSource step option) will also generate unique numbers for you.





    • User999's avatar

      Yeah DataGen script step would actually work as well to create a random 5 digit number.


      I used Math.round(10000 + Math.random() * 90000);