Skip to content

prewritten functions generate random numbers, strings, trees, ... and helpful tools.

Notifications You must be signed in to change notification settings

Omar622/Random-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Random-genererator

It is a library written in c++ provides some functions generate random numbers, strings, trees, ... and some useful tools see all provided functions.

How to use

1- download the library besides your cpp file.

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.

provided functions

Here are the docs of all functions.

1. random seed

2. random number (int)

  • 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)
  • return data type

    • (int)
  • complexity

    • O(1)
  • see random32 example

3. random number (long long)

  • 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)
  • return data type

    • (long long)
  • complexity

    • O(1)
  • see random64 example

4. random huge number

  • 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)
  • return data type

    • (string)
  • complexity

    • O(1)
  • see random_huge_number example

5. random string

  • 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)
  • return data type

    • (string)
  • complexity

    • O(length)
  • see random_string example

6. pick random item form vector

  • 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)
  • see pick_random example

7. pick random item form vector and remove it

  • 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)
  • see pick_random_and_remove example

8. random_tree

  • 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).
    • 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.
  • 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)
  • see random_tree example

9. Random Permutation

  • author: Khaled Hegazy

  • brief

    • return random permutation consists of unique positive integers.
  • function name

    • random_permutation
  • params

    • length (int)
  • return data type

    • vector<int>
  • Complexity

    • O(length)
  • see random_permutation example

10. Random Binary String

  • author: Khaled Hegazy

  • brief

    • return random binary string conists of binary digits 0,1.
  • function name

    • random_binary_string
  • params

    • length (int)
  • return data type

    • string
  • Complexity

    • O(length)
  • see random_binary_string example

11. Random Flag

  • author: Khaled Hegazy

  • brief

    • return random boolean flag with value True,False.
  • function name

    • random_flag
  • params

    • none
  • return data type

    • bool
  • Complexity

    • O(1)
  • see random_flag example

12. Random Vowel

  • author: Sree Sayi Hrudai

  • updated by: Omar Abdelghani

  • brief

    • returns random vowel with values ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'].
  • function name

    • random_vowel
  • params

    • isUpper bool
      • Optional parameter
      • In case not given or give with value false, function will return lower vowel character
      • otherwise function will return upper vowel character
  • return data type

    • char
  • Complexity

    • O(1)
  • see random_vowel example

13. Random Matrix

  • author: Sree Sayi Hrudai

  • brief

    • returns a matrix with row rows and col columns and the values in the matrix are in range [low, high]
  • function name

    • random_matrix(row, col, low, high)
  • params

    • row - number of rows in the matrix
    • col - number of columns in the matrix
    • low - starting range
    • high- ending range
  • return data type

    • vector<vector<long long>>
  • Complexity

    • O(row * col)
  • see random_matrix example

Contribute

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.

Rules of contribution

  1. 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.
  2. add examples of using function in the examples directory.
  3. add docs about this function in README file in the same format. (do not forget to add your name and linkedin or github link 😀)

About

prewritten functions generate random numbers, strings, trees, ... and helpful tools.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages