Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. // genLin1.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #define M 4294967296 //2^32
  5. #define a 69069
  6. #define c 1
  7.  
  8. #include "stdafx.h"
  9. #include <iostream>
  10. using namespace std;
  11.  
  12. unsigned int getRand(unsigned int &Xn) {
  13. unsigned int res = (a * Xn + c) % M;
  14. Xn = res;
  15. return res;
  16. }
  17.  
  18. int main()
  19. {
  20. unsigned int Xn = 15;
  21.  
  22. int ranges[10] = { 0,0,0,0,0,0,0,0,0,0 };
  23. unsigned int res;
  24. double M10 = M / 10;
  25.  
  26. for (int i = 0; i < 100000;i++) {
  27. res = getRand(Xn);
  28.  
  29. if (res < M10) {
  30. ranges[0]++;
  31. }else if (res < M10 * 2) {
  32. ranges[1]++;
  33. }else if (res < M10 * 3) {
  34. ranges[2]++;
  35. }else if (res < M10 *4) {
  36. ranges[3]++;
  37. }else if (res < M10 * 5) {
  38. ranges[4]++;
  39. }else if (res < M10 * 6) {
  40. ranges[5]++;
  41. }else if (res < M10 * 7) {
  42. ranges[6]++;
  43. }else if (res < M10 * 8) {
  44. ranges[7]++;
  45. }else if (res <M10 * 9) {
  46. ranges[8]++;
  47. }else if (res <= M10 * 10) {
  48. ranges[9]++;
  49. }
  50. }
  51.  
  52. for (int i = 0;i < 10;i++) {
  53. cout << "[" << i * M10 << " ; " << (i + 1) * M10 << "] " << ranges[i] << endl;
  54. }
  55.  
  56.  
  57. return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement