Flutter random_x – generate random everything (almost)
random_x is a fantastic package library where you can randomly generate almost everything. This package was created by Joseph Yaduvanshi. As the author said: Random_X
is a Random Library For all of your random needs for your projects that you’ll ever need(possibly).
This library also offers several configurable parameters in a variety of functions, which you can utilize and tailor to your needs. If you don’t want the customization, I’ve given default values for each function.
This project is free and open source and is licensed with Apache-2.0 license. If you like to support this project, go to the project page on GitHub and there you can find support options.
So, how to use this flutter random_x library?
First, add this line of code to your package’s pubspec.yaml. You can skip the ward dependencies because it is already in that file :).
dependencies:
random_x: ^0.3.1
Next, import the package into your dart project file.
import 'package:random_x/random_x.dart';
The next step is the simplest one, just generate your random text or value. Below is the simplest example of the code.
Text(
RndX.generateName(),
),
The list of random_x generators
At the time of writing, there is a lot to randomly generate, and I will try to simply describe all below.
Generate a random name with RndX.generateName()
Generates first and second name i.e. Linea Garff.
Text(
RndX.generateName(),
),
Generate random names with RndX.generateNames()
Generates a list of names separated with ‘,’. toString() help to print the list in the Text widget.
Text(
RndX.generateNames(count: 3).toString(),
),
Generate a random username with RndX.generateUsername()
Generates the list of usernames. The randomNumberLength attribute defines how many random digits you want with your name i.e. [abcde12, cdeab23].
count (int): The number of usernames to generate. Defaults to 1.
randomNumberLength (int): The length of the random number that will be appended to the username. Defaults to 2
usernameLength (int): The length of the username. If not specified, it will be a random number between 5 and 10. Max length is 10
Text(
RndX.generateUsername(count: 2, randomNumberLength: 2).toString(),
),
Generate random sex with RndX.randomSex()
Simple, generate sex. we have three available outputs: female, male and other.
Text(
RndX.randomSex(),
),
Generate random race with RndX.randomRace()
Text(
RndX.randomRace(),
),
Generate a random birthday date with RndX.randomBirthday()
start (DateTime): The start date of the range.
end (DateTime): The end date of the range.
Text(
RndX.randomBirthday().toString(),
),
You can also define the start date and the end date.
Text(
RndX.randomBirthday(start: DateTime(1989), end: DateTime(2022)).toString(),
),
Generate a random date between dates with RndX.generateRandomDateBetween()
start (DateTime): The start date of the range.
end (DateTime): The end date of the range.
Text(
RndX.generateRandomDateBetween(start: DateTime(1988),
end: DateTime(1989)).toString(),
),
Generate a random future date with RndX.randomFutureDate()
Text(
RndX.randomFutureDate().toString(),
),
You can also define a start date and an end date.
start (DateTime): The start date for the random date to be generated.
end (DateTime): The end date of the range.
Text(
RndX.randomFutureDate(start: DateTime(2048), end: DateTime(2058)).toString(),
),
Generate a random past date with RndX.randomPastDate()
start (DateTime): The start date of the range.
end (DateTime): The end date of the range.
Text(
RndX.randomPastDate().toString(),
),
Text(
RndX.randomPastDate(start: DateTime(1990), end: DateTime(2000)).toString(),
),
Generate a random future date after a certain date with RndX.randomFutureDateAfter()
date (DateTime): The date to start the random date generation from.
Text(
RndX.randomFutureDateAfter(date: DateTime(2030)).toString(),
),
Generate a random past date before a certain date with RndX.randomPastDateBefore()
date (DateTime): The date to generate a random date before.
Text(
RndX.randomPastDateBefore(date: DateTime(2020)).toString(),
),
Generate a random date by age with RndX.randomDateByAge()
age (int): The age of the person.
Text(
RndX.randomDateByAge(age: 21).toString(),
),
Generate a random future date by age with RndX.randomFutureDateByAge()
age (int): The age of the person.
Text(
RndX.randomFutureDateByAge(age: 21).toString(),
),
Generate random dates with RndX.generateRandomDates()
Text(
RndX.generateRandomDates(count: 3, start: DateTime(1990),
end: DateTime(2000)).toString(),
),
count (int): The number of dates you want to generate. Defaults to 1
start (DateTime): The start date of the range.
end (DateTime): The end date of the range.
uniqueList (bool): If true, the list will be unique. If false, the list will not be unique.
Generate random zodiac signs with RndX.randomZodiacSign()
Text(
RndX.randomZodiacSign(),
),
Generate a random blood group with RndX.randomBloodGroup()
Text(
RndX.randomBloodGroup(),
),
Generate random hair colour with RndX.randomHairColor()
Text(
RndX.randomHairColor(),
),
Generate random eye colour with RndX.randomEyeColor()
Text(
RndX.randomEyeColor(),
),
Generate random height with RndX.randomHeight()
Text(
RndX.randomHeight(),
),
isMetric (bool): If true, the height will be in metric units. If false, it will be in imperial units. Defaults to false
withCentimeters (bool): If true, the height will be in the format of 5’10” (178 cm). If false, the height will be in the format of 5’10”. Defaults to true
Text(
RndX.randomHeight(isMetric: true, withCentimeters: true),
),
Generate random weight with RndX.randomHeight()
Text(
RndX.randomWeight(),
),
min (int): The minimum weight value. Defaults to 40
max (int): The maximum weight value. Defaults to 300
withKG (bool): If true, the weight will be returned with the KG unit. Defaults to true
Text(
RndX.randomWeight(min: 20, max: 100, withKG: true),
),
Generate a random postal code (UNITED STATES) with RndX.randomPostalCode()
Text(
RndX.randomPostalCode(),
),
Generate random address by street address with RndX.getRandomAddressByStreetAddress()
address1 (String): The street address of the address you want to get (UNITED STATES). I do not know what attribute to use as the address1 🙁
count (int): The number of addresses to return. Defaults to 1
Text(
RndX.getRandomAddressByStreetAddress(address1: '', count: 2).toString(),
),
Generate random address by city with RndX.getRandomAddressByCity()
city (String): The city (UNITED STATES) you want to get a random address from. Same as above, I do not know how to use it 🙁
count (int): The number of addresses you want to generate. Defaults to 1
Text(
RndX.getRandomAddressByCity(city: '', count: 2).toString(),
),
Generate random address by state with RndX.getRandomAddressByState()
state (String): The state (UNITED STATES) you want to get a random address from. Same as above, I do not know how to use it 🙁
count (int): The number of addresses you want to generate. Defaults to 1
Text(
RndX.getRandomAddressByState(state: 'New York', count: 2).toString(),
),
Generate a random city with RndX.generateRandomCity()
Text(
RndX.generateRandomCity(),
),
Generate random state with RndX.generateRandomState()
Text(
RndX.generateRandomState(),
),
Generate a random street address with RndX.generateRandomStreetAddress()
Text(
RndX.generateRandomStreetAddress(),
),
Generate random latitude with RndX.generateRandomLatitude()
Text(
RndX.generateRandomLatitude(),
),
Generate random longitude with RndX.generateRandomLongitude()
Text(
RndX.generateRandomLongitude(),
),
Generate a random Social Security Number with RndX.randomSSN()
Text(
RndX.randomSSN(),
),
count (int): The number of SSNs to generate. Defaults to 1
withdashes (bool): If you want the SSN to be formatted with dashes, set this to true. Default to false
Text(
RndX.randomSSN(count: 3, withdashes: true).toString(),
),
Generate random salary with RndX.randomSalary()
Text(
RndX.randomSalary(),
),
Generate random civil status with RndX.randomCivilStatus()
Text(
RndX.randomCivilStatus(),
),
generates a random educational background with RndX.randomEducationalBackground()
Text(
RndX.randomEducationalBackground(),
),
generates a random religion with RndX.randomReligion()
Text(
RndX.randomReligion(),
),
generates a random disease history with RndX.randomDiseaseHistory()
Text(
RndX.randomDiseaseHistory(),
),
generates a random employment status with RndX.randomEmploymentStatus()
Text(
RndX.randomEmploymentStatus(),
),
generates a random occupation with RndX.randomOccupation()
Text(
RndX.randomOccupation(),
),
generates a random vehicle with RndX.randoVehicle()
Text(
RndX.randoVehicle(),
),
generates a random hobby with RndX.randomHobbies()
RndX.randomHobbies(),
),
generates a random favorite color with RndX.randomFavoriteColor()
Text(
RndX.randomFavoriteColor(),
),
generates a random favorite food with RndX.randomFavoriteFood()
Text(
RndX.randomFavoriteFood(),
),
generates a random favorite music with RndX.randomFavoriteMusic()
Text(
RndX.randomFavoriteMusic(),
),
generates a random favorite movie with RndX.randomFavoriteMovie()
Text(
RndX.randomFavoriteMovie(),
),
generates a random favorite book with RndX.randomFavoriteBook()
Text(
RndX.randomFavoriteBook(),
),
generates a random favorite sports with RndX.randomFavoriteSports()
Text(
RndX.randomFavoriteSports(),
),
generates a random favorite genre with RndX.randomFavoriteGenre()
Text(
RndX.randomFavoriteGenre(),
),
generates a random device detail with RndX.randomCivirandomDeviceDetailStatus()
Text(
RndX.randomDeviceDetail(),
),
generates a random website with RndX.randomWebsite()
Text(
RndX.randomWebsite(),
),
You can generate a website with https or without. Use here true or false.
Text(
RndX.randomWebsite(https: false),
),
generates a random credit card number with RndX.randomFullCreditCard()
Text(
RndX.randomFullCreditCard().toString(),
),
generates a random CompleteUserDetailsModel object with RndX.randomCompletePersonDetails()
It generates all the above and some from below in one go.
Text(
RndX.randomCompletePersonDetails().toString(),
),
generates a random email address with RndX.generateEmail()
Text(
RndX.generateEmail(),
),
count (int): The number of emails to generate. Defaults to 1
randomNumberLength (int): The length of the random number that will be appended to the email. Default to 2
domain (String): The domain of the email address. Defaults to gmail.com
Text(
RndX.generateEmail(count: 2,
randomNumberLength: 3,
domain: 'gmail.com').toString(),
),
generate a random pseudo word with RndX.generateRandomPseudoWord()
Text(
RndX.generateRandomPseudoWord(maxWordSize: 8),
),
maxWordSize (int): The maximum size of the word to be generated.
constantWordSize (bool): If true, the word size will be the same for every word. Defaults to false
Text(
RndX.generateRandomPseudoWord(maxWordSize: 8, constantWordSize: true),
),
generates a list of random pseudo words with RndX.generateRandomPseudoWordList()
numOfWords (int): The number of words you want to generate.
maxWordSize (int): The maximum size of the word.
constantWordSize (bool): If true, all words will be the same size. Defaults to false
Text(
RndX.generateRandomPseudoWordList(numOfWords: 2, maxWordSize: 8, constantWordSize: true).toString(),
),
returns a randomized string with RndX.randomiseString()
string (String): The string to randomize.
length (int): The length of the string to be returned. This is not required.
Text(
RndX.randomiseString(string: 'abcdefghi', length: 6),
),
generates a random string of the specified length and type with RndX.randomString()
length (int): The length of the string to be generated.
type (RandomCharStringType): The type of string you want to generate.
RandomCharStringType
- upperCase
- lowerCase
- upperLower
- alphaNumerical
- specialCharASCII
Text(
RndX.randomString(type: RandomCharStringType.upperCase, length: 7),
),
randomizes a list of strings with RndX.randomiseList()
list (List): The list to randomize.
length (int): The length of the string to be generated. This is not required. length cannot be bigger than the list length.
Text(
RndX.randomiseList(list: ['asd', 'def', 'sdz', 'ert'], length: 3).toString(),
),
generates a random string from a list of strings with RndX.randStringFromListWithSeparatorAndRepeat_()
list (List): The list of characters to choose from.
length (int): The length of the string to be generated.
separator (String): The separator to use between the random characters.
Text(
RndX.randStringFromListWithSeparatorAndRepeat_(
list: ['asdfg', 'def', 'sdz', 'erth'],
length: 6,
separator: '/').toString(),
),
generates a random string from a list of strings with RndX.randStringFromListWithSeparator_()
Attributes as above.
Text(
RndX.randStringFromListWithSeparator_(
list: ['asdfg', 'def', 'sdz', 'erth'],
length: 6,
separator: '/').toString(),
),
generates a random string from a list of characters with RndX.randStringFromList_()
Attributes as above except the separator.
Text(
RndX.randStringFromList_(
list: ['asdfg', 'def', 'sdz', 'erth'],
length: 3,).toString(),
),
generates a random password with RndX.generatePassword()
Text(
RndX.generatePassword(),
),
count (int): The number of passwords to generate. Defaults to 1
uniqueList (bool): If true, the list of passwords will be unique. If false, the list of passwords will be non-unique. Defaults to true
length (int): The length of the password. Defaults to 8
minLowercase (int): The minimum number of lowercase characters to include in the password. Default to 3
minUppercase (int): The minimum number of uppercase letters to be included in the password. Default to 1
minNumbers (int): The minimum number of numbers that should be in the password. Default to 3
minSpecialCharacters (int): The minimum number of special characters to include in the password. Default to 3
Text(
RndX.generatePassword(
count: 1,
uniqueList: true,
length: 5,
minLowercase: 1,
minUppercase: 1,
minNumbers: 1,
minSpecialCharacters: 1
).toString(),
),
returns a random user agent string with RndX.getRandomUA()
count (int): The number of user agents you want to generate. Defaults to 1
type (UserAgentType): The type of user agent you want to generate. Defaults to UserAgentType
Text(
RndX.getRandomUA(),
),
UserAgentType
- UserAgentType.none
- UserAgentType.web
- UserAgentType.mobile
- UserAgentType.tablet
- UserAgentType.macOs
Text(
RndX.getRandomUA(count: 2, type: UserAgentType.tablet).toString(),
),
Generate a random UUID (Universally Unique Identifier) with RndX.genUUID()
Text(
RndX.genUUID(),
),
Generates a GUID with RndX.guid()
Text(
RndX.guid(),
),
allUpperCase (bool): Whether the GUID should be all upper case or not. Default to false
length (int): The length of the GUID. The default is 32. Default to 32
Text(
RndX.guid(allUpperCase: true, length: 24 ),
),
generates a random hash string in base64 format with RndX.randomHashBase64()
length (int): The length of the hash. Defaults to 32
allUpperCase (bool): If true, the hash will be all uppercase. Defaults to false
allLowerCase (bool): If true, the hash will be all lowercase. Defaults to false
Text(
RndX.randomHashBase64(),
),
Text(
RndX.randomHashBase64(allUpperCase: false, allLowerCase: false, length: 32 ),
),
generates a random MD5 hash V1 with RndX.randomMD5hashV1()
Text(
RndX.randomMD5hashV1(),
),
Attributes as above.
Text(
RndX.randomMD5hashV1(allUpperCase: false, length: 32),
),
generates a random MD5 hash V2 with RndX.randomMD5hashV2()
Text(
RndX.randomMD5hashV2(),
),
Attributes as above.
Text(
RndX.randomMD5hashV2(allUpperCase: false, length: 32),
),
generates a random SHA256 hash V1 with RndX.randomSHA256Hashv1()
Text(
RndX.randomSHA256Hashv1(),
),
Attributes as above.
Text(
RndX.randomSHA256Hashv1(allUpperCase: false, length: 32),
),
generates a random SHA256 hash V2 with RndX.randomSHA256Hashv2()
Text(
RndX.randomSHA256Hashv2(),
),
Attributes as above.
Text(
RndX.randomSHA256Hashv2(allUpperCase: false, length: 32),
),
generates a random SHA512 hash V1 with RndX.randomSHA512Hashv1()
Text(
RndX.randomSHA512Hashv1(),
),
Attributes as above.
Text(
RndX.randomSHA512Hashv1(allUpperCase: false, length: 32),
),
generates a random SHA512 hash V2 with RndX.randomSHA512Hashv2()
Text(
RndX.randomSHA512Hashv2(),
),
Attributes as above.
Text(
RndX.randomSHA512Hashv2(allUpperCase: false, length: 32),
),
generates a random SHA1 hash V1 with RndX.randomSHA1Hashv1()
Text(
RndX.randomSHA1Hashv1(),
),
Attributes as above.
Text(
RndX.randomSHA1Hashv1(allUpperCase: false, length: 32),
),
generates a random SHA1 hash V2 with RndX.randomSHA1Hashv2()
Text(
RndX.randomSHA1Hashv2(),
),
Attributes as above.
Text(
RndX.randomSHA1Hashv2(allUpperCase: false, length: 32),
),
generates a random SHA384 hash V1 with RndX.randomSHA384Hashv1()
Text(
RndX.randomSHA384Hashv1(),
),
Attributes as above.
Text(
RndX.randomSHA384Hashv1(allUpperCase: false, length: 32),
),
generates a random SHA384 hash V2 with RndX.randomSHA384Hashv2()
Text(
RndX.randomSHA384Hashv2(),
),
Attributes as above.
Text(
RndX.randomSHA384Hashv2(allUpperCase: false, length: 32),
),
generates a random SHA224 hash V1 with RndX.randomSHA224Hashv1()
Text(
RndX.randomSHA224Hashv1(),
),
Attributes as above.
Text(
RndX.randomSHA224Hashv1(allUpperCase: false, length: 32),
),
generates a random SHA224 hash V2 with RndX.randomSHA224Hashv2()
Text(
RndX.randomSHA224Hashv2(),
),
Attributes as above.
Text(
RndX.randomSHA224Hashv2(allUpperCase: false, length: 32),
),
generates a random HMAC hash with RndX.randomHMACHash()
Text(
RndX.randomHMACHash(),
),
Attributes as above.
Text(
RndX.randomHMACHash(allUpperCase: false, length: 32),
),
generates a random HMAC hash V2 with RndX.randomHMACHash()
Text(
RndX.randomHMACHashv2(),
),
Attributes as above.
Text(
RndX.randomHMACHashv2(allUpperCase: false, length: 32),
),
generates a random verification code with RndX.randomVerifcationCodes()
Text(
RndX.randomVerifcationCodes(),
),
length (int): The length of the verification code. Defaults to 9
useNumbers (bool): If true, the code will contain numbers. Defaults to true
useSpecialCharacters (bool): If true, the code will contain special characters. Defaults to false
useAlphabet (bool): If true, the code will contain alphabets. Defaults to false
useDashes (bool): If true, the code will be separated by dashes. Defaults to true
dashPosition (int): The position of the dash in the verification code. Defaults to 3
Text(
RndX.randomVerifcationCodes(
length: 8,
useNumbers: true,
useSpecialCharacters: true,
useAlphabet: true,
useDashes: true,
dashPosition: 3
),
),
Generates a random IMEI number with RndX.genIMEINumber()
Text(
RndX.genIMEINumber(),
),
Generates a random Zoom ID with RndX.randomZoomID()
Text(
RndX.randomZoomID(),
),
generates a random document ID for Firebase with RndX.firebaseRandomDocumentID()
Text(
RndX.firebaseRandomDocumentID(),
),
Generates a random Google API key with RndX.randomGoogleAPIKey()
Text(
RndX.randomGoogleAPIKey(),
),
Generates a random Google Client ID with RndX.randomGoogleClientID()
Text(
RndX.randomGoogleClientID(),
),
Generates a random Google Client Secret with RndX.randomGoogleClientSecret()
Text(
RndX.randomGoogleClientSecret(),
),
Generates a random Google Project ID with RndX.randomGoogleProjectID()
Text(
RndX.randomGoogleProjectID(),
),
Generates a random Google Storage bucket name with RndX.randomGoogleStorageBucket()
Text(
RndX.randomGoogleStorageBucket(),
),
generates a GUID with a separator with RndX.guidWithSeparator()
At the time of writing, I have a problem with this one. Basically, I tried different lengths but I am always getting errors, so, I guess this will be fixed in the future.
Text(
RndX.guidWithSeparator(
length: ,
separator: '-',
allUpperCase: true
),
),
generates a random phone number with RndX.generatePhoneNumber()
Text(
RndX.generatePhoneNumber().toString(),
),
You can also generate a list of numbers.
Text(
RndX.generatePhoneNumber(
count: 3,
uniqueList: true
).toString(),
),
returns a Gravatar image URL with RndX.getRandomAvatarUrl()
Text(
RndX.getRandomAvatarUrl(),
),
This returns the default gravatar image.
https://www.gravatar.com/avatar/d67b2be004605a474fd78b55f55cd82c?
More options:
email (String): The email address of the user.
defaultImage (GravatarImage): The default image to use if the user doesn’t have a gravatar.
forceDefault (bool): If true, always return the default image, never the user’s image. Defaults is false
fileExtension (bool): If true, the URL will have a file extension (ex: .jpg). Defaults to false
rating (GravatarRating): The maximum rating to allow.
SelectableText(
RndX.getRandomAvatarUrl(
email: ,
size: 128,
defaultImage: ,
forceDefault: true,
fileExtension: true,
rating:
),
),
This is the image returned without the email, default image and rating.

https://www.gravatar.com/avatar/4cfc012c17a3e50dc3c924af41ce89ac.png?s=128&f=y
returns the JSON URL of the avatar.
Text(
RndX.getavatarJsonUrl(),
),
This is the output.
https://www.gravatar.com/73cdc4d703a715d5bd397ff9a17222dc.json
returns the QR code URL of the avatar.
Text(
RndX.getAvatarQRUrl(),
),
generates a random IPV4 address.
Text(
RndX.generateRandomIPV4(),
),
Generate a random IPV6 address
Text(
RndX.generateRandomIPV6(),
),
Generate a random MAC address
Text(
RndX.generateRandomMAC(),
),
Generate Random Colors
- randomColor
- randomColorWithAlpha
- randomColorWithOpacity
- randomColorWithOpacityAndGreen
- randomPrimaryColor
- randomAccentColor
/// Generating a random color and applying it to the text.
Text(
"Generate Random Color",
style: TextStyle(
color: RndX.randomColor,
),
),
/// Generating a random color with alpha.
Text(
"Generate Random Color With Alpha",
style: TextStyle(
color: RndX.randomColorWithAlpha,
),
),
/// Generating a random color with random opacity.
Text(
"Generate Random Color With Random Opacity",
style: TextStyle(
color: RndX.randomColorWithOpacity,
),
),
/// Generating a random color with random opacity and greenish color.
Text(
"Generate Random Color With Random Opacity Greenish",
style: TextStyle(
color: RndX.randomColorWithOpacityAndGreen,
),
),
/// Generating a random color with random opacity and greenish.
Text(
"Generate Random Color With Random Opacity Redish",
style: TextStyle(
color: RndX.randomColorWithOpacityAndGreen,
),
),
/// Generating a random primary color and applying it to the text.
Text(
"Generate Random Primary Color",
style: TextStyle(
color: RndX.randomPrimaryColor,
),
),
/// Generating a random accent color.
Text(
"Generate Random Accent Color",
style: TextStyle(
color: RndX.randomAccentColor,
),
),
Link to the pub.dev project page
https://pub.dev/packages/random_x
This is the link to the project’s GitHub page
https://github.com/josephyaduvanshi/random_x