1
0

iwgen.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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, 1000000);
  11. * for (int i = 0; i < weight; i++)
  12. * result = max(result, rnd.next(1, 1000000));
  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, 1000000);
  18. * for (int i = 0; i < -weight; i++)
  19. * result = min(result, rnd.next(1, 1000000));
  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. #include <iostream>
  27. using namespace std;
  28. int main(int argc, char* argv[])
  29. {
  30. registerGen(argc, argv, 1);
  31. cout << rnd.wnext(1, 1000000, opt<int>(1)) << endl;
  32. return 0;
  33. }