Recently,
I have seen subscriber 's youtube channel, It is very useful and I thank all the coders who upload their screencasts and helping for the community.
Interesting thing is,
He uses some C++ code to generate random test cases to test his solution and to hack some other's solution
I would like to hear some tips on how to generate random test cases in C++ ?
Yeah , rand()
function can be used but shows same integer every time after it's execution.
So, It would be interesting, If some of the coders in this community share their tips on how to generate those test cases.
and also I can see that Far Manager Editor is pretty Powerful!, How to use it?
Any similar Editor on Linux Ubuntu ?
I even like to see tourist coding during codeforces/topcoder/codechef rounds.
Hope that he notices this post and uploads screen cast as Petr, Egor, subscriber, many others ... does :)
srand(time(NULL)); -_-
Do not. It will be reinitialized once a second only. Rather painful discovery, especially if you try using that for stress testing.
Cheat sheet for x86 (assuming GCC):
One can also try reading bytes from
/dev/urandom
on Linux and initialize generator with first several bytes.Now you can random any integer you like, marking the range using modular division
Without calling
srand(...)
or if you callsrand(x)
with the same x, therand()
function will be generating the same random sequence on every execution. It's actually pretty useful property which allows you to re-generate the same test case when you re-run the program (e.g. if you want to debug your solution). So you can still generate a test case even without callingsrand(...)
and you should usesrand(...)
only if you want to reset the random sequence.By the way, Codeforces requires your generator to be predictable (as far as I know), that is, it should print same output regardless of current time, i.e. you should use fixed random seed.
This rule can't be held because in other way every right hash solution could have been easily hacked. It would have been nonsense.
Codeforces does require test generators to generate tests reproducibly, as per point 29 here.
Codeforces does not require solutions to generate answers reproducibly.
Yes, solutions using reproducible hashing can be hacked in a contest.