iwgen.cpp 990 B

12345678910111213141516171819202122232425262728293031323334
  1. /*
  2. * Outputs weighted random number between 1 and 10^6, inclusive.
  3. * To generate different values, call "nwgen.exe weight".
  4. *
  5. * If parameter "weight"
  6. * is equals to 0 than used uniformly distributed random.
  7. *
  8. * If parameter "weight" > 0 then you can think about it as code like this:
  9. * <code>
  10. * result = rnd.next(1, 1'000'000);
  11. * for (int i = 0; i < weight; i++)
  12. * result = max(result, rnd.next(1, 1'000'000));
  13. * </code>
  14. *
  15. * If parameter "weight" < 0 then you can think about it as code like this:
  16. * <code>
  17. * result = rnd.next(1, 1'000'000);
  18. * for (int i = 0; i < -weight; i++)
  19. * result = min(result, rnd.next(1, 1'000'000));
  20. * </code>
  21. *
  22. * It is typical behaviour of "wnext" methods to use this strategy to
  23. * generate off-center random distribution.
  24. */
  25. #include "testlib.h"
  26. using namespace std;
  27. int main(int argc, char *argv[]) {
  28. registerGen(argc, argv, 1);
  29. println(rnd.wnext(1, 1'000'000, opt<int>(1)));
  30. }