swagata93's blog

By swagata93, history, 5 years ago, In English

I couldn't understand the meaning of the following code which is part of a program...It will be very helpful if anyone clarify this...Thank you all!!

#ifdef ONPC
  mt19937 rnd(228);
#else
  mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif
  • Vote: I like it
  • +8
  • Vote: I do not like it

| Write comment?
»
5 years ago, # |
Rev. 2   Vote: I like it +8 Vote: I do not like it

It is initializing a random number generator. If it's on the author's personal computer (#ifdef ONPC), then he initializes it with a set seed (228), so it is easier to debug, because it provides the exact same numbers every time. If it is on the Codeforces judge system (#else), then he initializes it with a basically unpredictable number based on the system time, which prevents people in his room from hacking him (by submitting a test case on which the random number generator degrades to worst-case performance).