{"id":25952035,"url":"https://github.com/pandoraeartha/highperformancerandomengine","last_synced_at":"2026-04-28T17:33:46.120Z","repository":{"id":280621577,"uuid":"942594143","full_name":"PandoraEartha/HighPerformanceRandomEngine","owner":"PandoraEartha","description":"Head only high performance pseudorandom engine base on PCG-XSH-RR. Multithreading allowed, easy to use, statistically good. 仅有头文件的随机引擎, 基于PCG-XSH-RR算法, 允许多线程, 简单易用, 高随机性. ","archived":false,"fork":false,"pushed_at":"2025-03-04T11:50:42.000Z","size":24,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-04T12:29:05.498Z","etag":null,"topics":["c","cpp","random","random-generation"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PandoraEartha.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-04T10:56:22.000Z","updated_at":"2025-03-04T11:50:45.000Z","dependencies_parsed_at":"2025-03-04T12:39:55.893Z","dependency_job_id":null,"html_url":"https://github.com/PandoraEartha/HighPerformanceRandomEngine","commit_stats":null,"previous_names":["pandoraeartha/highperformancerandomengine"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PandoraEartha%2FHighPerformanceRandomEngine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PandoraEartha%2FHighPerformanceRandomEngine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PandoraEartha%2FHighPerformanceRandomEngine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PandoraEartha%2FHighPerformanceRandomEngine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PandoraEartha","download_url":"https://codeload.github.com/PandoraEartha/HighPerformanceRandomEngine/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241865177,"owners_count":20033306,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","cpp","random","random-generation"],"created_at":"2025-03-04T14:32:45.783Z","updated_at":"2026-04-28T17:33:46.114Z","avatar_url":"https://github.com/PandoraEartha.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"[中文介绍](https://zhuanlan.zhihu.com/p/27708881274)\n\n# High Performance C Random Engine\nHead only high performance pseudorandom engine base on PCG-XSH-RR. Multithreading allowed, easy to use, statistically good. \n\n仅有头文件的随机引擎, 基于PCG-XSH-RR算法, 允许多线程, 简单易用, 随机性强. \n\n## How to use\n\n`#include \"PCG32.h\"`\n\n```\nPCG32Struct PCGStatus;\nPCG32SetSeed(\u0026PCGStatus,time(NULL));\ndouble random=PCG32UniformReal(\u0026PCGStatus,-1,999);\n```\n\nnote:\n\n1.Remember to set the seed. 记得设置种子. \n\n2.Use its own `PCG32Struct` in each thread function and set different seed. 每个线程函数采用各自的`PCG32Struct`并且设置单独的种子\n\n# Functions \n\n`void PCG32SetSeed(PCG32Struct* status,long long unsigned int seed);`\n\nSet the seed of PCG random engine and initlize \n\n初始化随机引擎, 设置随机种子\n\n`unsigned PCG32(PCG32Struct* status);`\n\nGenerate a unsigned type random number in range of [0,0xFFFFFFFF(4294967295)]\n\n产生[0,0xFFFFFFFF(4294967295)]范围的`unsigned`类型的随机整数\n\n`unsigned PCG32Uniform(PCG32Struct* status,unsigned min,unsigned max);`\n\nGenerate a unsigned type random number that obey uniform distrubution in range of [min,max]\n\n产生[min,max]范围的`unsigned`类型的随机整数\n\n`double PCG32UniformReal(PCG32Struct* status,double min,double max);`\n\nGenerate a double type random number that obey uniform distrubution in range of [min,max]\n\n产生[min,max]范围的`double`类型的随机整数\n\n`double PCG32StandardNormal(PCG32Struct* status);`\n\nGenerate a double type random number that obey standard normal distrubution\n\n产生`double`类型的服从标准正态分布的随机数\n\n`void PCG32UniformShuffle(PCG32Struct* status,unsigned* array,unsigned length);`\n\nShuffling, swaps elements in the input sequence to ensure that every element etc. can appear anywhere in the array.\n\n洗牌, 对输入序列进行元素交换, 保证每个元素等可能的出现在数组中任意位置. \n\n`unsigned PCG32Uniform_Strict(PCG32Struct* status,const unsigned min,const unsigned max);`\n\nGenerate a unsigned type random number that obey uniform distrubution in range of [min,max], `max` can not smaller than `min` and gap(`max`-`min`) can not be power of 2\n\n产生[min,max]范围的`unsigned`类型的随机整数, `max`不能小于`min`且gap(`max`-`min`)不能是2的幂\n\n\n# Performance\n\nPerformance test base on 13490F WSL2 Ubuntu, built using g++ 14.02. Compare with `std::default_random_engine` in C++ `random`. The result below shows the time consuming on generating 4074074037 random number on spicific distribution.\n\n性能测试基于13490F WSL2 Ubuntu, 采用g++ 14.02编译. 与C++`random`库中的`std::default_random_engine`进行比较. 下面的结果显示了在特定分布上生成4074074037随机数所花费的时间. \n\n![image](https://github.com/user-attachments/assets/80df23e7-8cc0-43ed-885a-6817652c5654)\n\n## Uniform Real Distribution \n\n![image](https://github.com/user-attachments/assets/37c8ee99-9fec-4b91-8cc9-c41bf580cf78)\n\n`PCG32UniformReal` is 8.6399 times faster than `std::uniform_real_distribution`\n\n`PCG32UniformReal` 比 `std::uniform_real_distribution` 快8.6399倍\n\n## Normal Distribution \n\n![image](https://github.com/user-attachments/assets/a0038c41-7b70-4ec0-a77e-4215777b70dc)\n\n`PCG32StandardNormal` is 5.8596 times faster than `std::normal_distribution`\n\n`PCG32StandardNormal` 比 `std::normal_distribution` 快5.8596倍\n\n## Base Generator\n\n![image_2025-03-04_21-08-13](https://github.com/user-attachments/assets/66eb203c-1693-461d-9fa4-733996eb8351)\n\n`PCG32` is 1.9767 times faster than `std::default_random_engine`\n\n`PCG32` 比`std::default_random_engine`快1.9898倍\n\n## Uniform Unsigned\n\n![image_2025-03-04_21-10-18](https://github.com/user-attachments/assets/30c4da1d-7ad5-47da-a976-3c3783f3ac56)\n\n`PCG32Uniform` is 1.7713 times faster than `std::uniform_int_distribution\u003cunsigned\u003e`\n\n`PCG32Uniform` 比 `std::uniform_int_distribution\u003cunsigned\u003e` 快1.7713倍\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpandoraeartha%2Fhighperformancerandomengine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpandoraeartha%2Fhighperformancerandomengine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpandoraeartha%2Fhighperformancerandomengine/lists"}