diff options
| author | jdhao <jdhao@hotmail.com> | 2021-06-29 14:52:42 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-06-29 14:52:42 +0800 |
| commit | 1719e784332e57bc23767eea05d137e5912e0071 (patch) | |
| tree | edd50d99997ccf6dda3308394b0e43802347608a /my_snippets | |
| parent | 0c05b15dac744a5f1a058fb5aca09ec2d0f47395 (diff) | |
Add more cpp snippets
Diffstat (limited to 'my_snippets')
| -rw-r--r-- | my_snippets/cpp.snippets | 17 |
1 files changed, 17 insertions, 0 deletions
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<random> +vector<int> genRandom(int low, int high, int len){ + std::random_device rd; + std::mt19937 gen(rd()); + std::uniform_int_distribution<int> distribution(low, high); + + vector<int> arr(len, 0); + for (int i = 0; i != len; ++i){ + arr[i] = distribution(gen); + } + + return arr; +} +endsnippet |
