PRNG Analysis

cplus


1:0.001029
2:0.001044
3:0.000989
4:0.001045
5:0.001006
6:0.001054
7:0.001041
8:0.001039
9:0.001014
10:0.001065
11:0.001038
12:0.000977
13:0.001039
14:0.000977
15:0.001034
16:0.001009
17:0.001064
18:0.001061
19:0.001082
20:0.001001
21:0.001003
22:0.000967
23:0.000973
24:0.000948
25:0.000971
26:0.001042
27:0.001052
28:0.00103
29:0.00104
30:0.000952
31:0.001017
32:0.001014
33:0.000978
34:0.000983
35:0.001029
36:0.000978
37:0.000993
38:0.001029
39:0.001065
40:0.000961
41:0.000972
42:0.000996
43:0.000977
44:0.001018
45:0.001024
46:0.001038
47:0.000998
48:0.001007
49:0.000983
50:0.001006
51:0.000988
52:0.000983
53:0.001048
54:0.000931
55:0.000996
56:0.000963
57:0.001055
58:0.000991
59:0.001026
60:0.000995
61:0.001
62:0.000997
63:0.001006
64:0.001041
65:0.001
66:0.001065
67:0.001056
68:0.000995
69:0.000963
70:0.000968
71:0.000996
72:0.001053
73:0.000988
74:0.001078
75:0.001031
76:0.00101
77:0.001034
78:0.000986
79:0.000994
80:0.000967
81:0.000983
82:0.000998
83:0.000971
84:0.000994
85:0.001041
86:0.001008
87:0.000968
88:0.000992
89:0.001002
90:0.000999
91:0.000989
92:0.001028
93:0.000997
94:0.000975
95:0.001027
96:0.001006
97:0.001026
98:0.001072
99:0.000935
100:0.001005
101:0.00097
102:0.00105
103:0.00103
104:0.00101
105:0.001008
106:0.000984
107:0.001014
108:0.000986
109:0.000982
110:0.001063
111:0.001008
112:0.000988
113:0.001002
114:0.000971
115:0.000985
116:0.000996
117:0.000992
118:0.001034
119:0.000993
120:0.001008
121:0.001027
122:0.001016
123:0.000994
124:0.001041
125:0.00098
126:0.001007
127:0.000983
128:0.000895
129:0.000993
130:0.001049
131:0.001022
132:0.000965
133:0.001013
134:0.001047
135:0.000942
136:0.001024
137:0.001001
138:0.001002
139:0.000989
140:0.001024
141:0.001003
142:0.001002
143:0.000963
144:0.000959
145:0.000999
146:0.000973
147:0.001022
148:0.000975
149:0.001002
150:0.000995
151:0.001027
152:0.001027
153:0.000976
154:0.001017
155:0.001068
156:0.001001
157:0.001004
158:0.001028
159:0.000951
160:0.000996
161:0.001029
162:0.000979
163:0.001005
164:0.001014
165:0.001005
166:0.000966
167:0.000994
168:0.001014
169:0.000988
170:0.001002
171:0.001008
172:0.001
173:0.00099
174:0.000954
175:0.001066
176:0.000956
177:0.001095
178:0.000992
179:0.000964
180:0.001008
181:0.000973
182:0.001018
183:0.000929
184:0.001011
185:0.000976
186:0.001014
187:0.001019
188:0.001031
189:0.000986
190:0.001035
191:0.00104
192:0.00106
193:0.000996
194:0.000952
195:0.000977
196:0.00101
197:0.001032
198:0.001013
199:0.001025
200:0.00102
201:0.000979
202:0.001006
203:0.001052
204:0.001019
205:0.001009
206:0.001014
207:0.001039
208:0.000956
209:0.001007
210:0.000989
211:0.000997
212:0.001009
213:0.00104
214:0.000999
215:0.001034
216:0.000958
217:0.000985
218:0.001034
219:0.00101
220:0.000927
221:0.000957
222:0.001044
223:0.001038
224:0.000986
225:0.000978
226:0.001
227:0.001008
228:0.000973
229:0.001024
230:0.000992
231:0.001009
232:0.001035
233:0.000973
234:0.000959
235:0.001001
236:0.001028
237:0.000942
238:0.000998
239:0.000976
240:0.000946
241:0.001001
242:0.000972
243:0.000967
244:0.000992
245:0.000926
246:0.001067
247:0.001006
248:0.001023
249:0.000996
250:0.001017
251:0.000955
252:0.001009
253:0.001076
254:0.001016
255:0.001032
256:0.001022
257:0.000988
258:0.001043
259:0.000981
260:0.000969
261:0.00096
262:0.000961
263:0.001002
264:0.001075
265:0.001079
266:0.000993
267:0.00101
268:0.000931
269:0.001019
270:0.001008
271:0.000952
272:0.000984
273:0.000988
274:0.000915
275:0.00092
276:0.001014
277:0.001032
278:0.000971
279:0.001014
280:0.000948
281:0.00101
282:0.000982
283:0.000978
284:0.001033
285:0.000975
286:0.001022
287:0.000993
288:0.00096
289:0.001003
290:0.000963
291:0.000982
292:0.000931
293:0.001033
294:0.001062
295:0.001013
296:0.00099
297:0.001064
298:0.000984
299:0.001048
300:0.001016
301:0.001017
302:0.000986
303:0.001028
304:0.00099
305:0.001036
306:0.001009
307:0.001013
308:0.001069
309:0.001027
310:0.001001
311:0.001007
312:0.00106
313:0.000992
314:0.000995
315:0.001006
316:0.000966
317:0.001019
318:0.001001
319:0.000974
320:0.001013
321:0.000963
322:0.000967
323:0.00102
324:0.000962
325:0.001018
326:0.001019
327:0.000971
328:0.000968
329:0.001034
330:0.00098
331:0.000992
332:0.001
333:0.001027
334:0.000984
335:0.001
336:0.000985
337:0.000954
338:0.001013
339:0.000978
340:0.000983
341:0.001005
342:0.000972
343:0.00093
344:0.001022
345:0.000923
346:0.000997
347:0.000995
348:0.000972
349:0.001025
350:0.001004
351:0.001027
352:0.001073
353:0.001017
354:0.001042
355:0.000971
356:0.00094
357:0.000997
358:0.00102
359:0.001013
360:0.001063
361:0.001033
362:0.000932
363:0.001012
364:0.001007
365:0.000986
366:0.001008
367:0.001001
368:0.001059
369:0.001012
370:0.000995
371:0.000982
372:0.000956
373:0.000901
374:0.000948
375:0.001009
376:0.001026
377:0.001004
378:0.000982
379:0.001045
380:0.001001
381:0.000966
382:0.000979
383:0.001004
384:0.000998
385:0.000971
386:0.000974
387:0.001058
388:0.001025
389:0.00098
390:0.001026
391:0.001012
392:0.000989
393:0.001023
394:0.001022
395:0.001036
396:0.00099
397:0.001033
398:0.00098
399:0.000983
400:0.000995
401:0.001001
402:0.001047
403:0.000953
404:0.00098
405:0.001019
406:0.001032
407:0.000972
408:0.00103
409:0.001051
410:0.000976
411:0.000935
412:0.000977
413:0.000939
414:0.001009
415:0.000972
416:0.000981
417:0.001003
418:0.000996
419:0.001015
420:0.000999
421:0.001
422:0.001005
423:0.001056
424:0.001022
425:0.001029
426:0.000982
427:0.001038
428:0.001005
429:0.000991
430:0.001003
431:0.001035
432:0.00098
433:0.00099
434:0.001012
435:0.001008
436:0.001054
437:0.000987
438:0.000971
439:0.000969
440:0.001008
441:0.001011
442:0.001005
443:0.00101
444:0.000981
445:0.000976
446:0.000971
447:0.000947
448:0.000996
449:0.000989
450:0.000979
451:0.001
452:0.001007
453:0.001014
454:0.001064
455:0.001048
456:0.001009
457:0.000961
458:0.001002
459:0.001063
460:0.000981
461:0.000979
462:0.000996
463:0.00105
464:0.001028
465:0.000964
466:0.001045
467:0.000985
468:0.000989
469:0.000977
470:0.000983
471:0.001001
472:0.001003
473:0.001023
474:0.000935
475:0.000997
476:0.001017
477:0.001019
478:0.000955
479:0.00102
480:0.001027
481:0.001026
482:0.000968
483:0.000956
484:0.000983
485:0.000998
486:0.000974
487:0.000981
488:0.001051
489:0.000987
490:0.001042
491:0.000972
492:0.001
493:0.000975
494:0.001026
495:0.000995
496:0.000916
497:0.000959
498:0.000973
499:0.000964
500:0.00101
501:0.001019
502:0.001038
503:0.001001
504:0.000993
505:0.000988
506:0.000996
507:0.001047
508:0.000957
509:0.001083
510:0.000989
511:0.000984
512:0.000929
513:0.001007
514:0.000992
515:0.000949
516:0.001031
517:0.001043
518:0.001029
519:0.001015
520:0.001071
521:0.001043
522:0.000993
523:0.001009
524:0.000987
525:0.000947
526:0.000983
527:0.001017
528:0.000991
529:0.000992
530:0.001019
531:0.00097
532:0.000975
533:0.001012
534:0.000997
535:0.000999
536:0.000968
537:0.001022
538:0.001023
539:0.001
540:0.000999
541:0.001006
542:0.000989
543:0.001003
544:0.000982
545:0.00096
546:0.001057
547:0.001008
548:0.001016
549:0.000961
550:0.001031
551:0.001055
552:0.000986
553:0.000997
554:0.001015
555:0.001065
556:0.000995
557:0.000972
558:0.000981
559:0.000949
560:0.001036
561:0.001014
562:0.001014
563:0.00101
564:0.001012
565:0.00094
566:0.000957
567:0.001032
568:0.000999
569:0.00102
570:0.001067
571:0.001007
572:0.000989
573:0.000997
574:0.00106
575:0.001029
576:0.000968
577:0.001048
578:0.001005
579:0.000977
580:0.000963
581:0.000982
582:0.000985
583:0.000996
584:0.00104
585:0.000979
586:0.001011
587:0.001028
588:0.001006
589:0.000975
590:0.001016
591:0.001066
592:0.00098
593:0.000975
594:0.001026
595:0.001018
596:0.00098
597:0.001017
598:0.001021
599:0.00101
600:0.000998
601:0.000973
602:0.000976
603:0.001008
604:0.000991
605:0.000973
606:0.000987
607:0.000993
608:0.000963
609:0.000988
610:0.000974
611:0.000979
612:0.001028
613:0.000961
614:0.001034
615:0.001013
616:0.000951
617:0.000993
618:0.000993
619:0.000971
620:0.000982
621:0.001039
622:0.000986
623:0.001013
624:0.000976
625:0.001007
626:0.001007
627:0.001
628:0.000944
629:0.001006
630:0.000992
631:0.001034
632:0.000975
633:0.000965
634:0.001054
635:0.000898
636:0.000967
637:0.000992
638:0.000973
639:0.000999
640:0.000966
641:0.000956
642:0.000963
643:0.000972
644:0.001
645:0.000985
646:0.00097
647:0.001007
648:0.000987
649:0.000951
650:0.000952
651:0.000995
652:0.001004
653:0.00099
654:0.000973
655:0.000952
656:0.000992
657:0.000999
658:0.00092
659:0.001015
660:0.000944
661:0.000993
662:0.001001
663:0.001011
664:0.001003
665:0.001024
666:0.00102
667:0.001011
668:0.000997
669:0.001011
670:0.000981
671:0.00101
672:0.001021
673:0.000934
674:0.001022
675:0.000976
676:0.001022
677:0.000958
678:0.000986
679:0.001048
680:0.000981
681:0.001012
682:0.001021
683:0.000977
684:0.000997
685:0.000956
686:0.001056
687:0.001009
688:0.000951
689:0.001007
690:0.000971
691:0.001024
692:0.000976
693:0.000972
694:0.001066
695:0.00105
696:0.00098
697:0.001021
698:0.001061
699:0.001005
700:0.001015
701:0.000985
702:0.001025
703:0.000993
704:0.00099
705:0.001026
706:0.000942
707:0.001029
708:0.001021
709:0.001037
710:0.001011
711:0.001035
712:0.001055
713:0.001014
714:0.001023
715:0.000994
716:0.000961
717:0.000997
718:0.000994
719:0.001006
720:0.000998
721:0.000997
722:0.000973
723:0.000999
724:0.001016
725:0.000964
726:0.00101
727:0.001008
728:0.000968
729:0.000974
730:0.000987
731:0.001006
732:0.000962
733:0.000976
734:0.000988
735:0.001075
736:0.001046
737:0.00109
738:0.001047
739:0.001055
740:0.000993
741:0.000915
742:0.000963
743:0.001022
744:0.001044
745:0.000968
746:0.000957
747:0.001039
748:0.000998
749:0.000948
750:0.000974
751:0.000998
752:0.000997
753:0.001027
754:0.00096
755:0.001009
756:0.000978
757:0.000971
758:0.001024
759:0.001002
760:0.000994
761:0.00095
762:0.000962
763:0.001041
764:0.000984
765:0.000992
766:0.000963
767:0.000972
768:0.000999
769:0.000963
770:0.001083
771:0.001027
772:0.00101
773:0.001001
774:0.001013
775:0.000992
776:0.001009
777:0.001005
778:0.001029
779:0.001001
780:0.00101
781:0.001014
782:0.001
783:0.001033
784:0.000958
785:0.000996
786:0.001038
787:0.001057
788:0.000968
789:0.000987
790:0.001028
791:0.001025
792:0.000962
793:0.001027
794:0.000934
795:0.001056
796:0.000978
797:0.001007
798:0.000976
799:0.001037
800:0.001025
801:0.001015
802:0.001047
803:0.001035
804:0.00099
805:0.000995
806:0.000965
807:0.001008
808:0.001003
809:0.000957
810:0.000988
811:0.00099
812:0.00101
813:0.001008
814:0.000933
815:0.000957
816:0.000976
817:0.000973
818:0.000999
819:0.000972
820:0.001021
821:0.000976
822:0.001042
823:0.001044
824:0.001036
825:0.001011
826:0.00096
827:0.001015
828:0.001048
829:0.001014
830:0.000953
831:0.00101
832:0.000981
833:0.001037
834:0.000979
835:0.001022
836:0.001005
837:0.000973
838:0.000989
839:0.001042
840:0.000985
841:0.001017
842:0.000992
843:0.000971
844:0.001034
845:0.000962
846:0.001005
847:0.001001
848:0.000982
849:0.001041
850:0.001028
851:0.000994
852:0.000978
853:0.000992
854:0.001043
855:0.000972
856:0.000993
857:0.000926
858:0.000982
859:0.001
860:0.001021
861:0.000967
862:0.000982
863:0.001053
864:0.000993
865:0.001036
866:0.000968
867:0.001003
868:0.00105
869:0.001025
870:0.001
871:0.001024
872:0.001016
873:0.000985
874:0.000953
875:0.001087
876:0.001045
877:0.000995
878:0.001006
879:0.001028
880:0.001009
881:0.000997
882:0.001032
883:0.000948
884:0.000978
885:0.001024
886:0.000993
887:0.001081
888:0.000997
889:0.001023
890:0.000993
891:0.000959
892:0.000995
893:0.000946
894:0.000965
895:0.001011
896:0.001004
897:0.000991
898:0.001029
899:0.000981
900:0.001038
901:0.000983
902:0.001015
903:0.00103
904:0.001008
905:0.000997
906:0.001028
907:0.001011
908:0.00098
909:0.001013
910:0.001011
911:0.00103
912:0.00097
913:0.000979
914:0.000994
915:0.001072
916:0.000999
917:0.001022
918:0.000977
919:0.000956
920:0.001007
921:0.000988
922:0.001007
923:0.001004
924:0.001006
925:0.000985
926:0.001005
927:0.001015
928:0.001033
929:0.000973
930:0.001048
931:0.000973
932:0.001065
933:0.000977
934:0.000989
935:0.001031
936:0.000971
937:0.001018
938:0.001046
939:0.000955
940:0.000999
941:0.00093
942:0.000967
943:0.000983
944:0.000998
945:0.00102
946:0.000997
947:0.000961
948:0.001045
949:0.000995
950:0.001027
951:0.000982
952:0.001003
953:0.000965
954:0.001005
955:0.00098
956:0.000976
957:0.001011
958:0.001029
959:0.00091
960:0.001001
961:0.001004
962:0.001002
963:0.001024
964:0.000985
965:0.000968
966:0.000934
967:0.000965
968:0.000975
969:0.000951
970:0.001017
971:0.001005
972:0.000991
973:0.001029
974:0.000945
975:0.000973
976:0.001013
977:0.000971
978:0.00096
979:0.000981
980:0.001012
981:0.000987
982:0.000983
983:0.000992
984:0.000989
985:0.000992
986:0.000991
987:0.000926
988:0.001005
989:0.000969
990:0.000999
991:0.00098
992:0.001001
993:0.001048
994:0.000952
995:0.000988
996:0.000973
997:0.000986
998:0.001038
999:0.000996
1000:0.001018
1:0.0999921
2:0.100012
3:0.099995
4:0.0999926
5:0.099991
6:0.100016
7:0.0999973
8:0.0999919
9:0.100009
10:0.100004
1:0.099857
2:0.099955
3:0.100118
4:0.099814
5:0.100197
6:0.100489
7:0.10005
8:0.09982
9:0.099242
10:0.100458

#include <algorithm>
#include <fstream>
#include <iostream>
#include <map>
#include <random>
#include <string>
#include <vector>

const int N = 1000000;
const int X = 1000;

// g++ -std=c++17 cplus.cc -o cc

// Generate N random numbers between 1 and X
std::vector<int> generate_random_numbers()
{
    std::random_device rd;
    std::mt19937 mt(rd());
    std::uniform_int_distribution<int> dist(1, X);

    std::vector<int> numbers;
    for (int i = 0; i < N; i++)
    {
        numbers.push_back(dist(mt));
    }

    return numbers;
}

// Calculate the probability of each number
std::map<int, double> calculate_probabilities(const std::vector<int> &numbers)
{
    std::map<int, int> counts;
    for (auto number : numbers)
    {
        counts[number]++;
    }

    std::map<int, double> probabilities;
    for (const auto &kvp : counts)
    {
        probabilities[kvp.first] = (double)kvp.second / N;
    }

    return probabilities;
}

// Generate a file name based on the values of N and X
std::string generate_file_name()
{
    return "cplus_" + std::to_string(X) + "_" + std::to_string(N);
}

int main()
{
    // Generate the random numbers and calculate their probabilities
    auto numbers = generate_random_numbers();
    auto probabilities = calculate_probabilities(numbers);

    // Generate a file name and create the "outputs" directory if it does not exist
    auto file_name = generate_file_name();
    // std::filesystem::create_directories("outputs");

    // Write the probabilities to a file in the "outputs" directory
    std::ofstream file("../outputs/" + file_name);
    for (const auto &kvp : probabilities)
    {
        file << kvp.first << ":" << kvp.second << "\n";
    }

    return 0;
}