It is a library written in c++
provides some functions generate random numbers, strings, trees, ... and some useful tools see all provided functions.
1- download the library besides your cpp
file.
git clone [email protected]:Omar622/Random-generator.git
2 - include the header file of the library random_generator_lib.h
in the cpp file you are working on.
#include "random_generator_lib.h"
see the include example.
Here are the docs of all functions.
-
author: Omar Abdelghani
-
brief
- It is a random number generator (RNG)
mt19937
. see more about mt19937
- It is a random number generator (RNG)
-
function name
random_seed
-
params
- no parameters
-
return data type
(unsigned int)
32-bit unsigned integer
-
complexity
O(1)
-
author: Omar Abdelghani
-
updated by: ALi Ibrahim
-
brief
- return random integer number in given range [low, high].
- the chosen number is uniformly distributed.
- using random seed.
- if the given low greater than the given high, function will throw error
(random32 parameters is invalid)
.
-
function name
random32
-
params
- low
(int)
- high
(int)
- low
-
return data type
(int)
-
complexity
O(1)
-
see random32 example
-
author: Omar Abdelghani
-
updated by: ALi Ibrahim
-
brief
- return random long long number in given range [low, high].
- the chosen number is uniformly distributed.
- using random seed.
- if the given low greater than the given high, function will throw error
(random64 parameters is invalid)
.
-
function name
random64
-
params
- low
(long long)
- high
(long long)
- low
-
return data type
(long long)
-
complexity
O(1)
-
see random64 example
-
author: Omar Abdelghani
-
brief
- return very big valid random number as string.
- every chosen digit is uniformly distributed using random seed.
-
function name
random_huge_number
-
params
- length
(int)
- length
-
return data type
(string)
-
complexity
O(1)
-
author: Omar Abdelghani
-
brief
- return random string consists of only lower case letters.
- every chosen character is uniformly distributed using random seed.
-
function name
random_string
-
params
- length
(int)
- length
-
return data type
(string)
-
complexity
O(length)
-
author: Omar Abdelghani
-
brief
- return random item from the given vector.
- using random seed.
-
function name
pick_random
-
params
vector
of any data type
-
return data type
- same as vector data type
-
complexity
O(1)
-
author: Omar Abdelghani
-
brief
- return random item from the given vector then remove the chosen item.
- using random seed.
- the order of the given vector will be changed after using this function.
-
function name
pick_random_and_remove
-
params
vector
of any data type
-
return data type
- same as vector data type
-
complexity
O(1)
-
author: Omar Abdelghani
-
updated by: Eddard
-
brief
- return random tree given number of nodes, root and height.
- every node will have a unique id from 1 to number of nodes.
- in case not given any parameter they will be chosen randomly.
- in case given not valid root or height, the function will choose the nearest valid root and height.
-
function name
random_tree
-
params
- number of nodes
(int)
.- in case not given it will be chosen randomly in range [1, 100000] using random number (int).
- root id
(int)
.- expected an integer in range [1, number of nodes parameter].
- in case not given it will be chosen randomly in range [1, number of nodes] using random number (int).
- in case given not valid root, the function will choose the nearest valid root id.
- height
(int)
.- expected an integer in range [0, number of nodes parameter - 1].
- in case not given it will be chosen randomly in range [0, number of nodes parameter - 1] using random number (int).
- in case given not valid height, the function will choose the nearest valid height.
- number of nodes
-
return data type
vector<pair<int, int>>
- the size of the vector will be equal to (number of nodes - 1).
- each pair in the vector represents a directed edge in the tree.
(pair.first -> pair.second)
-
complexity
O(number of nodes)
-
author: Khaled Hegazy
-
brief
- return random permutation consists of unique positive integers.
-
function name
random_permutation
-
params
- length
(int)
- length
-
return data type
vector<int>
-
Complexity
O(length)
-
author: Khaled Hegazy
-
brief
- return random binary string conists of binary digits
0
,1
.
- return random binary string conists of binary digits
-
function name
random_binary_string
-
params
- length
(int)
- length
-
return data type
string
-
Complexity
O(length)
-
author: Khaled Hegazy
-
brief
- return random boolean flag with value
True
,False
.
- return random boolean flag with value
-
function name
random_flag
-
params
none
-
return data type
bool
-
Complexity
O(1)
-
author: Sree Sayi Hrudai
-
brief
- returns random vowel with values ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'].
-
function name
random_vowel_lower
random_vowel_upper
-
params
none
-
return data type
char
-
Complexity
O(1)
-
author: Sree Sayi Hrudai
-
brief
- returns a matrix with
row
rows andcol
columns and the values in the matrix are in range [low, high]
- returns a matrix with
-
function name
random_matrix(row, col, low, high)
-
params
row
- number of rows in the matrixcol
- number of columns in the matrixlow
- starting rangehigh
- ending range
-
return data type
vector<vector<long long>>
-
Complexity
O(row * col)
If you want to contribute ๐ค to this library, you're always welcome! you can contribute by implementing random function generating something doesn't exist in the library and this function is almost needed.
- your function
- works correctly.
- add comments in your code and the brief comment above your function.
- the brief comment must be in the same format as other briefs.
- the function is almost needed.
- add examples of using function in the examples directory.
- add docs about this function in README file in the same format. (do not forget to add your name and linkedin or github link ๐)