Make Selenium Easy

Generate random numbers using Javafaker API – Java

Introduction

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

Output

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.

Output

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.
#ThanksForReading
#HappyLearning

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

Author: Amod Mahajan

My name is Amod Mahajan and I am an IT employee with 6+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went through so many selenium tutorials. Thanks to Mukesh Otwani as his tutorials are easy and cover basics to advance. I have habit of exploring concepts by deep diving. I used to make notes. I thought of sharing my knowledge through posts and now I am here. #KeepLearning #ShareLearning

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.

Generate random numbers using Javafaker API – Java

by Amod Mahajan time to read: 1 min
1
%d bloggers like this: