random_data module#
Tools to create random Python builtin objects.
- COMPLEX_TYPES = (<class 'list'>, <class 'dict'>)#
Types that are collections (string excluded)
- DATETIME_MINIMUM = datetime.datetime(1970, 1, 1, 0, 0, tzinfo=datetime.timezone.utc)#
The minimum value for a valid date
- MAX_LEVEL_DEPTH = 4#
Maximum nesting level of complex types
- SIMPLE_TYPES = (<class 'str'>, <class 'int'>, <class 'float'>, <class 'datetime.datetime'>, <class 'NoneType'>)#
Default types that are not collections (string included)
- VALID_TIMEZONES = ['America/Boa_Vista', 'America/Cuiaba', 'Asia/Manila', 'Pacific/Auckland', 'Australia/Darwin', 'Pacific/Ponape', 'Etc/Universal', 'America/Rankin_Inlet', 'Europe/Prague', 'Europe/Uzhgorod', 'Africa/El_Aaiun', 'Asia/Dhaka', 'America/Rio_Branco', 'Asia/Bishkek', 'Pacific/Rarotonga', 'Jamaica', 'Singapore', 'Asia/Jakarta', 'Pacific/Wallis', 'Africa/Kampala', 'Chile/EasterIsland', 'Etc/GMT-2', 'Europe/Astrakhan', 'Atlantic/Faroe', 'America/Dawson_Creek', 'America/Matamoros', 'Africa/Timbuktu', 'America/Argentina/Salta', 'HST', 'EST', 'America/Puerto_Rico', 'Asia/Ulan_Bator', 'Etc/GMT+3', 'Etc/GMT-5', 'Europe/Moscow', 'Etc/GMT+12', 'Australia/Victoria', 'US/East-Indiana', 'Europe/Vilnius', 'Europe/Zagreb', 'America/Swift_Current', 'Africa/Ceuta', 'GMT+0', 'GB-Eire', 'America/Argentina/Rio_Gallegos', 'Europe/Helsinki', 'CET', 'America/Argentina/Mendoza', 'Asia/Ujung_Pandang', 'Asia/Thimphu', 'Asia/Macau', 'WET', 'Brazil/West', 'Pacific/Palau', 'Pacific/Marquesas', 'Africa/Porto-Novo', 'Europe/Berlin', 'America/Marigot', 'Etc/GMT+10', 'Europe/Riga', 'America/Montevideo', 'Israel', 'America/Maceio', 'Asia/Bangkok', 'Africa/Mogadishu', 'US/Arizona', 'US/Hawaii', 'Asia/Muscat', 'America/Belem', 'Europe/Lisbon', 'America/Pangnirtung', 'Etc/GMT+7', 'Africa/Abidjan', 'America/Porto_Acre', 'Antarctica/McMurdo', 'America/Aruba', 'Asia/Calcutta', 'America/Winnipeg', 'Asia/Baghdad', 'America/Fortaleza', 'Asia/Harbin', 'Asia/Kuwait', 'America/Sao_Paulo', 'Pacific/Wake', 'Etc/GMT-9', 'Pacific/Kanton', 'America/Thule', 'Europe/Saratov', 'US/Central', 'Africa/Bissau', 'GMT', 'Asia/Aqtobe', 'Asia/Kuching', 'Africa/Djibouti', 'Antarctica/Syowa', 'Asia/Tbilisi', 'America/Indiana/Knox', 'Japan', 'Asia/Atyrau', 'Africa/Freetown', 'Hongkong', 'Canada/Newfoundland', 'UTC', 'America/Cayman', 'America/Dawson', 'America/Indiana/Marengo', 'Asia/Tomsk', 'America/Hermosillo', 'America/Kentucky/Monticello', 'America/Indiana/Tell_City', 'Europe/Sarajevo', 'America/Belize', 'Pacific/Niue', 'Asia/Riyadh', 'UCT', 'America/Juneau', 'America/Boise', 'America/Ensenada', 'Asia/Barnaul', 'Europe/Luxembourg', 'Mexico/BajaSur', 'Africa/Blantyre', 'Canada/Central', 'Etc/GMT-1', 'Europe/Guernsey', 'Antarctica/Macquarie', 'Africa/Asmera', 'Pacific/Easter', 'Europe/San_Marino', 'Asia/Qatar', 'America/Guayaquil', 'Asia/Yerevan', 'America/Chicago', 'Asia/Dili', 'Asia/Choibalsan', 'Pacific/Midway', 'America/North_Dakota/New_Salem', 'Europe/Skopje', 'Canada/Saskatchewan', 'Europe/Kyiv', 'America/Santiago', 'America/Sitka', 'America/Halifax', 'Mexico/BajaNorte', 'Asia/Tashkent', 'Antarctica/Davis', 'Europe/Tirane', 'Europe/Paris', 'Africa/Nairobi', 'Asia/Vientiane', 'America/Dominica', 'ROK', 'America/Argentina/La_Rioja', 'Pacific/Saipan', 'Africa/Johannesburg', 'Asia/Beirut', 'Africa/Mbabane', 'Etc/GMT', 'Asia/Thimbu', 'Etc/GMT+6', 'America/Yellowknife', 'America/Inuvik', 'Pacific/Funafuti', 'Asia/Aden', 'America/Argentina/ComodRivadavia', 'Europe/Nicosia', 'Australia/Canberra', 'America/St_Lucia', 'America/Nome', 'America/Nipigon', 'America/Paramaribo', 'Canada/Eastern', 'Etc/GMT+2', 'Atlantic/Bermuda', 'Europe/Monaco', 'Europe/Tiraspol', 'Asia/Shanghai', 'Pacific/Fakaofo', 'America/Cordoba', 'Asia/Ho_Chi_Minh', 'Brazil/DeNoronha', 'Australia/Adelaide', 'Australia/Currie', 'Africa/Asmara', 'Etc/GMT+11', 'Asia/Sakhalin', 'Europe/Brussels', 'America/Yakutat', 'Pacific/Nauru', 'Europe/Malta', 'Indian/Comoro', 'NZ', 'America/Monterrey', 'Pacific/Kiritimati', 'Asia/Rangoon', 'Australia/LHI', 'Europe/Minsk', 'Pacific/Tarawa', 'Africa/Luanda', 'Asia/Pontianak', 'Africa/Harare', 'Europe/Vienna', 'America/North_Dakota/Beulah', 'Asia/Bahrain', 'Atlantic/Madeira', 'Atlantic/Canary', 'Europe/Busingen', 'America/Atikokan', 'Africa/Bamako', 'Asia/Magadan', 'Europe/Gibraltar', 'Etc/GMT0', 'Indian/Maldives', 'America/Whitehorse', 'Europe/Vaduz', 'America/Merida', 'America/Glace_Bay', 'Europe/Belgrade', 'Australia/ACT', 'Antarctica/Rothera', 'America/Lima', 'Eire', 'Pacific/Chatham', 'Africa/Tunis', 'Pacific/Tahiti', 'America/Metlakatla', 'America/Bogota', 'Africa/Ouagadougou', 'America/Tijuana', 'EST5EDT', 'Indian/Christmas', 'Europe/Kiev', 'America/Asuncion', 'America/Fort_Nelson', 'Asia/Jerusalem', 'America/Santarem', 'Europe/Bucharest', 'Africa/Kinshasa', 'Navajo', 'America/Grand_Turk', 'Europe/Bratislava', 'Etc/GMT-3', 'Etc/GMT-11', 'Europe/Isle_of_Man', 'Asia/Dushanbe', 'America/Guyana', 'Australia/South', 'America/Virgin', 'Asia/Jayapura', 'Asia/Omsk', 'America/Kralendijk', 'Indian/Cocos', 'America/Atka', 'CST6CDT', 'America/North_Dakota/Center', 'Europe/Zurich', 'Asia/Macao', 'Asia/Hebron', 'America/Detroit', 'Asia/Chungking', 'America/Argentina/Jujuy', 'Asia/Oral', 'Australia/Hobart', 'America/Argentina/Tucuman', 'America/Toronto', 'localtime', 'Factory', 'Asia/Saigon', 'Asia/Taipei', 'Australia/Sydney', 'Indian/Antananarivo', 'Canada/Pacific', 'Pacific/Pitcairn', 'Europe/Amsterdam', 'Atlantic/St_Helena', 'Antarctica/South_Pole', 'Europe/Vatican', 'America/Edmonton', 'America/Mexico_City', 'Etc/GMT-14', 'Africa/Lubumbashi', 'Europe/Belfast', 'Asia/Famagusta', 'Europe/Jersey', 'Asia/Hovd', 'Poland', 'Asia/Ashgabat', 'Asia/Aqtau', 'Indian/Mayotte', 'America/Bahia_Banderas', 'Asia/Chongqing', 'Africa/Banjul', 'Indian/Reunion', 'Atlantic/Reykjavik', 'Pacific/Guam', 'Africa/Niamey', 'Antarctica/Casey', 'Australia/Lindeman', 'Europe/Stockholm', 'Asia/Irkutsk', 'America/Cayenne', 'Canada/Yukon', 'Asia/Nicosia', 'America/Mazatlan', 'America/Blanc-Sablon', 'Asia/Katmandu', 'America/Antigua', 'Cuba', 'Asia/Kolkata', 'Etc/GMT+0', 'America/Managua', 'Indian/Mauritius', 'America/Ciudad_Juarez', 'Pacific/Port_Moresby', 'MET', 'Asia/Ashkhabad', 'Africa/Douala', 'Asia/Srednekolymsk', 'Etc/Greenwich', 'ROC', 'America/Grenada', 'America/Nuuk', 'America/Montreal', 'GMT-0', 'America/Montserrat', 'Europe/Oslo', 'America/Recife', 'Asia/Tehran', 'Europe/Podgorica', 'America/Eirunepe', 'Antarctica/Mawson', 'Asia/Hong_Kong', 'America/Curacao', 'Asia/Brunei', 'Etc/GMT+8', 'Pacific/Bougainville', 'Turkey', 'Africa/Tripoli', 'Etc/GMT+4', 'Australia/Perth', 'America/Coral_Harbour', 'America/St_Johns', 'Europe/Copenhagen', 'Europe/Simferopol', 'Brazil/Acre', 'Asia/Kamchatka', 'W-SU', 'America/La_Paz', 'America/Buenos_Aires', 'America/Fort_Wayne', 'Europe/Istanbul', 'Australia/Brisbane', 'Etc/GMT+5', 'Pacific/Gambier', 'America/Caracas', 'America/Noronha', 'Africa/Nouakchott', 'America/Rosario', 'Asia/Dacca', 'America/Danmarkshavn', 'EET', 'America/Argentina/Cordoba', 'Europe/Mariehamn', 'Europe/Rome', 'Atlantic/Stanley', 'Pacific/Guadalcanal', 'America/Anchorage', 'Brazil/East', 'America/Creston', 'Etc/GMT-6', 'Africa/Windhoek', 'Australia/Tasmania', 'Atlantic/Cape_Verde', 'Pacific/Fiji', 'America/Adak', 'Antarctica/Palmer', 'Asia/Kathmandu', 'America/Argentina/Catamarca', 'America/Guadeloupe', 'Indian/Mahe', 'Africa/Bujumbura', 'Africa/Dakar', 'Africa/Accra', 'Africa/Cairo', 'Asia/Tel_Aviv', 'America/Panama', 'Etc/GMT+1', 'America/Port_of_Spain', 'Asia/Tokyo', 'Pacific/Yap', 'GB', 'Asia/Samarkand', 'US/Alaska', 'Atlantic/South_Georgia', 'Asia/Krasnoyarsk', 'MST', 'US/Mountain', 'Europe/Sofia', 'America/Porto_Velho', 'Antarctica/DumontDUrville', 'Asia/Chita', 'Pacific/Samoa', 'Zulu', 'America/Guatemala', 'Arctic/Longyearbyen', 'America/Nassau', 'MST7MDT', 'America/Los_Angeles', 'Europe/Zaporozhye', 'Atlantic/Azores', 'America/Thunder_Bay', 'Africa/Conakry', 'Africa/Khartoum', 'Africa/Bangui', 'Universal', 'Europe/Athens', 'Pacific/Apia', 'Africa/Dar_es_Salaam', 'Africa/Libreville', 'America/Mendoza', 'Etc/GMT-8', 'Asia/Almaty', 'America/Indiana/Vevay', 'America/Chihuahua', 'Iran', 'Etc/UCT', 'America/Martinique', 'America/Resolute', 'America/New_York', 'America/Tegucigalpa', 'Asia/Kashgar', 'Asia/Novosibirsk', 'Canada/Atlantic', 'US/Eastern', 'Asia/Baku', 'Africa/Malabo', 'America/Vancouver', 'America/Argentina/Buenos_Aires', 'Europe/Warsaw', 'Pacific/Pago_Pago', 'Australia/Queensland', 'Indian/Kerguelen', 'Pacific/Honolulu', 'Asia/Pyongyang', 'US/Michigan', 'America/Kentucky/Louisville', 'Asia/Damascus', 'Kwajalein', 'Egypt', 'America/Rainy_River', 'Libya', 'Asia/Karachi', 'Europe/Volgograd', 'Iceland', 'Europe/Kirov', 'America/Cancun', 'Pacific/Pohnpei', 'Atlantic/Jan_Mayen', 'Asia/Kuala_Lumpur', 'Asia/Amman', 'Pacific/Efate', 'America/Manaus', 'Canada/Mountain', 'America/Indiana/Winamac', 'Europe/London', 'America/Denver', 'Etc/GMT-13', 'America/Bahia', 'America/Jujuy', 'Etc/GMT-4', 'US/Pacific', 'Etc/GMT+9', 'Etc/GMT-12', 'America/Anguilla', 'America/Barbados', 'Australia/Lord_Howe', 'America/Argentina/San_Luis', 'Africa/Maseru', 'US/Aleutian', 'PST8PDT', 'America/Havana', 'Asia/Qostanay', 'Australia/West', 'America/Indianapolis', 'PRC', 'Asia/Urumqi', 'Atlantic/Faeroe', 'Asia/Ust-Nera', 'Etc/GMT-10', 'Mexico/General', 'Africa/Casablanca', 'Asia/Khandyga', 'America/Regina', 'Africa/Sao_Tome', 'America/St_Thomas', 'Europe/Ulyanovsk', 'Africa/Lusaka', 'Antarctica/Vostok', 'US/Indiana-Starke', 'Africa/Lagos', 'Pacific/Noumea', 'America/Costa_Rica', 'NZ-CHAT', 'America/Campo_Grande', 'America/Port-au-Prince', 'America/St_Barthelemy', 'Antarctica/Troll', 'America/Punta_Arenas', 'America/St_Kitts', 'Australia/North', 'Australia/Broken_Hill', 'Europe/Ljubljana', 'Europe/Chisinau', 'Etc/GMT-7', 'Etc/UTC', 'Pacific/Majuro', 'Asia/Yangon', 'Greenwich', 'Portugal', 'America/Jamaica', 'America/Indiana/Indianapolis', 'America/Indiana/Petersburg', 'America/Goose_Bay', 'America/El_Salvador', 'America/Godthab', 'Asia/Makassar', 'Indian/Chagos', 'America/Indiana/Vincennes', 'America/Knox_IN', 'Pacific/Tongatapu', 'America/Miquelon', 'Europe/Madrid', 'Australia/Yancowinna', 'Asia/Gaza', 'Africa/Maputo', 'Europe/Kaliningrad', 'Australia/NSW', 'Asia/Yakutsk', 'America/Menominee', 'America/Araguaina', 'Asia/Singapore', 'America/Santa_Isabel', 'America/Scoresbysund', 'Europe/Samara', 'Asia/Qyzylorda', 'Chile/Continental', 'America/Santo_Domingo', 'America/St_Vincent', 'America/Iqaluit', 'America/Phoenix', 'Africa/Lome', 'Asia/Yekaterinburg', 'Asia/Colombo', 'Etc/Zulu', 'Asia/Anadyr', 'Asia/Vladivostok', 'Africa/Juba', 'Asia/Seoul', 'America/Lower_Princes', 'Asia/Novokuznetsk', 'Africa/Addis_Ababa', 'America/Ojinaga', 'Pacific/Kwajalein', 'Europe/Tallinn', 'Africa/Monrovia', 'Africa/Ndjamena', 'Europe/Budapest', 'America/Cambridge_Bay', 'America/Louisville', 'Europe/Andorra', 'America/Argentina/Ushuaia', 'Asia/Kabul', 'Pacific/Galapagos', 'Pacific/Kosrae', 'America/Shiprock', 'Africa/Algiers', 'Pacific/Johnston', 'Asia/Phnom_Penh', 'US/Samoa', 'Asia/Ulaanbaatar', 'Pacific/Norfolk', 'Australia/Melbourne', 'America/Argentina/San_Juan', 'America/Moncton', 'Africa/Gaborone', 'Asia/Istanbul', 'Etc/GMT-0', 'America/Tortola', 'Pacific/Chuuk', 'GMT0', 'Asia/Dubai', 'Pacific/Enderbury', 'Europe/Dublin', 'America/Catamarca', 'Australia/Eucla', 'Pacific/Truk', 'Africa/Kigali', 'Africa/Brazzaville']#
List of timezone names
- randdatetime()#
Returns a random datetime after
DATETIME_MINIMUM
- randdict(list_value_type=None, total_items=10, level=1)[source]#
Dict that contains random items, but all keys are
str
- Parameters:
list_value_type (type | None) – Type of items for
list
s. If not given, it can be any fromRANDOM_FUNC_BY_TYPE
.total_items (int) – Number of items in the
dict
without considering nesting.level (int) – Controls how likely it is to get a complex type. Higher values make it more unlikely. Values over
MAX_LEVEL_DEPTH
returns alwaysSIMPLE_TYPES
. It increases automatically for nesteddict
s andlist
s.
- Returns:
A
dict
filled with random items .
- randfloat()#
random() -> x in the interval [0, 1).
- randlist(value_type=None, total_items=10, level=1)[source]#
Createss a list that contains
total_items
random items, all of the same type.- Parameters:
value_type (type | None) – One of the types in
RANDOM_FUNC_BY_TYPE
. Defines the type of the objects inside the list. If not given a random type is selectedtotal_items (int) – Total number of items in the list. Defaults to 10.
level (int) – Controls how likely it is to get a complex type. Higher values make it more unlikely. Values over
MAX_LEVEL_DEPTH
returns alwaysSIMPLE_TYPES
.
- Returns:
A list filled with random items.
- randstr()#
Returns a random string of ascii letters, ‘_’ and ‘-’
- randtimezone()#
Returns a random
zoneinfo.ZoneInfo
- randtypes(level=1, n=1)[source]#
Returns a random type from
RANDOM_FUNC_BY_TYPE
- Parameters:
level (int) – Controls how likely it is to get a complex type. Higher values make it more unlikely. Values over
MAX_LEVEL_DEPTH
returns alwaysSIMPLE_TYPES
.n (int) –
- Returns:
A list of
type
s fromRANDOM_FUNC_BY_TYPE
.- Return type:
list[type]