Code Monkey home page Code Monkey logo

random-generator's Introduction

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

  • 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)
  • 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 ๐Ÿ˜€)

random-generator's People

Contributors

omar622 avatar hrudai2002 avatar khaledhegazy222 avatar ali-ibrahim137 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.