Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // genLin1.cpp : Defines the entry point for the console application.
- //
- #define M 4294967296 //2^32
- #define a 69069
- #define c 1
- #include "stdafx.h"
- #include <iostream>
- using namespace std;
- unsigned int getRand(unsigned int &Xn) {
- unsigned int res = (a * Xn + c) % M;
- Xn = res;
- return res;
- }
- int main()
- {
- unsigned int Xn = 15;
- int ranges[10] = { 0,0,0,0,0,0,0,0,0,0 };
- unsigned int res;
- double M10 = M / 10;
- for (int i = 0; i < 100000;i++) {
- res = getRand(Xn);
- if (res < M10) {
- ranges[0]++;
- }else if (res < M10 * 2) {
- ranges[1]++;
- }else if (res < M10 * 3) {
- ranges[2]++;
- }else if (res < M10 *4) {
- ranges[3]++;
- }else if (res < M10 * 5) {
- ranges[4]++;
- }else if (res < M10 * 6) {
- ranges[5]++;
- }else if (res < M10 * 7) {
- ranges[6]++;
- }else if (res < M10 * 8) {
- ranges[7]++;
- }else if (res <M10 * 9) {
- ranges[8]++;
- }else if (res <= M10 * 10) {
- ranges[9]++;
- }
- }
- for (int i = 0;i < 10;i++) {
- cout << "[" << i * M10 << " ; " << (i + 1) * M10 << "] " << ranges[i] << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement