Generate Random Guid (5 digits)
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Generate Random Guid (5 digits)
Hi,
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?
Thanks
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hey @Rememo
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.
Cheers,
Rich
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yeah DataGen script step would actually work as well to create a random 5 digit number.
I used Math.round(10000 + Math.random() * 90000);
