/Random-generator

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

Primary LanguageC++

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.

  • git clone git@github.com: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.

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

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 😀)