diff --git a/my_snippets/cpp.snippets b/my_snippets/cpp.snippets index 7e18d52..1cf3b7e 100644 --- a/my_snippets/cpp.snippets +++ b/my_snippets/cpp.snippets @@ -47,3 +47,20 @@ endsnippet snippet cout "print a variable" w cout << "$1: " << $2 << endl; endsnippet + +snippet random "Generate a random list" b +// Generate a random sequence of length len, in range(low, high) (inclusive). +// need to #include +vector genRandom(int low, int high, int len){ + std::random_device rd; + std::mt19937 gen(rd()); + std::uniform_int_distribution distribution(low, high); + + vector arr(len, 0); + for (int i = 0; i != len; ++i){ + arr[i] = distribution(gen); + } + + return arr; +} +endsnippet