1
0
mirror of https://github.com/jdhao/nvim-config.git synced 2025-06-08 14:14:33 +02:00

Add more cpp snippets

This commit is contained in:
jdhao 2021-06-29 14:52:42 +08:00 committed by GitHub
parent 0c05b15dac
commit 1719e78433
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -47,3 +47,20 @@ endsnippet
snippet cout "print a variable" w snippet cout "print a variable" w
cout << "$1: " << $2 << endl; cout << "$1: " << $2 << endl;
endsnippet 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