You have no understood the problem of your code. Because your code creates random values its runtime complexity cannot be determined. Because of your '+2' and '-1' it is also possible for the program to never end. However, this is not likely but possible, thus one can only say it is O(infinite).
Usual cases of the bigO notation:
You have only one loop:
for(int k=0;k<n;++k) {}
this comes to O(n), because you have n iterations
Two or more loops in sequence:
for(int k=0;k<n;++k) {}
for(int l=0;l<n;++l) {}
comes to O(2*n), but constants do not matter on bigO, so it is O(n)
Entangled loops:
for(int k=0;k<n;++k) {
for(int l=0;l<n;++l) {
}
}
is O(n²),
for(int k=0;k<n;++k) {
for(int l=0;l<n;++l) {
for(int m=0;m<n;++m) {
}
}
}
is O(n³) and so on
And the most common complexity you will encounter for search/comparison algorithms is
for(int k=0;k<n;++k) {
for(int l=k;l<n;++l) {// note here: l=k instead of l=0
}
}
Is O(n*log(n))
For more details use google.