Make Selenium Easy

Generate random numbers using Javafaker API – Java


We may require to generate random numbers in programming languages for multiple purposes like test data creation or numeric IDs for employees etc. We have multiple libraries available to generate random numbers in Java but I personally feel Javafaker APIs are easier to use compared to others.

We will learn to generate random whole numbers, decimal numbers, and also within a range in this post.

I have covered an introductory post on Javafaker API here.

Maven Dependency

I have used below Javafaker API dependency:-

Generate random numbers

Faker class in Javafaker library provides utility methods for generating fake strings, such as names, phone numbers, addresses. generate random strings with given patterns.

Generate a random digit


Generate number within a range

Generating a random number within a range is required at many times and I think Javafaker provides the easiest way to do so.


There are many useful methods provided by the Javafaker library which you can explore and learn about.

You can clone above Git Repo from here.

You can subscribe to my YouTube channel RetargetCommon to learn from video tutorials.

If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.

Find all Selenium related posts here, all API manual and automation related posts here, and find frequently asked Java Programs here.

Author: Amod Mahajan

A software Tester who is paid to judge products developed by others. Currently getting paid in American Dollars. Writing technical posts and creating YouTube videos are my hobbies.

1 thought on “Generate random numbers using Javafaker API – Java

Leave a Reply

Please wait...

Subscribe to new posts to become automation expert

Want to be notified when my new post is published? Get my posts in your inbox.