{"id":23692520,"url":"https://github.com/microcontroleurmonde/pyboard_rng","last_synced_at":"2026-01-17T08:30:21.406Z","repository":{"id":265535556,"uuid":"896211122","full_name":"MicroControleurMonde/PyBOARD_RNG","owner":"MicroControleurMonde","description":"Implementation in micro-python of the `pyb.rng()` function to generate random numbers.","archived":false,"fork":false,"pushed_at":"2024-12-13T15:37:37.000Z","size":11007,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-30T03:28:24.208Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MicroControleurMonde.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2024-11-29T19:33:49.000Z","updated_at":"2024-12-18T18:32:40.000Z","dependencies_parsed_at":"2024-11-29T20:38:51.592Z","dependency_job_id":null,"html_url":"https://github.com/MicroControleurMonde/PyBOARD_RNG","commit_stats":null,"previous_names":["microcontroleurmonde/pyboard_rng"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MicroControleurMonde%2FPyBOARD_RNG","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MicroControleurMonde%2FPyBOARD_RNG/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MicroControleurMonde%2FPyBOARD_RNG/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MicroControleurMonde%2FPyBOARD_RNG/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MicroControleurMonde","download_url":"https://codeload.github.com/MicroControleurMonde/PyBOARD_RNG/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239758828,"owners_count":19692033,"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":[],"created_at":"2024-12-30T03:28:37.705Z","updated_at":"2026-01-17T08:30:21.350Z","avatar_url":"https://github.com/MicroControleurMonde.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PyBOARD_RNG\n\n![pic](https://github.com/MicroControleurMonde/PyBOARD_RNG/blob/main/Reports/MicroPython.jpg)\n\n**Abstract:** Micro-python implementation of the **`pyb.rng()`** function to generate random numbers **FOR TESTING PURPOSES**. \n\nThe function specifically calls the hardcoded RNG in the chip directly (*as for the ESP32*)\n\n## Generator coding:\n\nHere is a typical example of use :\n\n    import pyb\n    random_number = pyb.rng()  # Returns a 32-bit random number\n    print(random_number)\n    \n    Output: 112922794\nI made a very basic code that makes 200'000 calls to the 'pyb.rng()' function. Here: [pyboard_rng.py](https://github.com/MicroControleurMonde/PyBOARD_RNG/blob/main/pyboard_rng.py)\n\n### Note:\nUnlike the ESP32 board, **I did not rewrite the RNG module** which is perfectly functional natively for the Pyboard board in micropython.\n\nThe goal here is more to test the performance and RNG capabilities of the MCU than to code anything.\n\n## Performance:\n\n- Time spent to generate 200'000 values: **108 seconds** (avg)\n- Throughput: **7,407 bytes/sec**\n- **1847** random values / sec.\n\n## Ent/DJent Test Report:\n\n(www.fourmilab.ch) John Walker and [David Johnston](https://github.com/dj-on-github/djent)\n##### Max possible enropy = 1   \n-    Min Entropy (by max occurrence of symbol 0) = 0.912487\n-    Shannon IID Entropy = **0.997177** bits per symbol\n\n- Sample size: **53.4 MB**\n- Total generated: **13'336'713 values**\n- [Ent Report -Raw](https://github.com/MicroControleurMonde/PyBOARD_RNG/blob/main/Reports/Pyb_RNG_Test_13Mi_djent.txt)\n- [Ent Report Analyse]***To be updated***\n\n## CAcert Report:\n[Results page](https://www.cacert.at/cgi-bin/rngresults)\n\n![pic](https://github.com/MicroControleurMonde/PyBOARD_RNG/blob/main/Reports/CACert_Pyb_RNG_Test_13Mil.png)\n\n\n## Dieharder Test Report\n\n(https://webhome.phy.duke.edu/~rgb/General/dieharder.php) Robert G. Brown\n\n- Sample size: **53.4 MB**\n- Total generated: **13'336'713  values**\n- [Dieharder Report - Raw](https://github.com/MicroControleurMonde/PyBOARD_RNG/blob/main/Reports/Pyb_RNG_Test_13Mi_dieharder.txt)\n- [Dieharder Report Analyses] ***To be updated***\n\n## Reference:\n[Reference manual STM32F405/415](https://www.st.com/resource/en/reference_manual/rm0090-stm32f405415-stm32f407417-stm32f427437-and-stm32f429439-advanced-armbased-32bit-mcus-stmicroelectronics.pdf) (page 770 - 24 Random number generator)\n\nDoc. excerpt:\n\n        The RNG processor is a random number generator, based on continuous analogue noise, \n        which provides a 32-bit random value to the host when read.\n        The RNG passed the FIPS PUB 140-2 tests (10 October 2001) with a pass rate of 99%.\n\n        The analogue circuit consists of several ring oscillators whose outputs are combined\n        by XOR to generate the seeds. \n        The RNG_LFSR is clocked by a dedicated clock (RNG_CLK) at a constant frequency, \n        so that the quality of the random number is independent of the HCLK frequency.\n        The contents of the RNG_LFSR are transferred to the data register (RNG_DR) when \n        a significant number of seeds have been entered into the RNG_LFSR.\n        In parallel, the analogue seed and the dedicated RNG_CLK clock are monitored. \n        Status bits (in the RNG_SR register) indicate when an abnormal sequence occurs \n        on the seed or when the RNG_CLK clock frequency is too low. \n        An interrupt can be generated when an error is detected.\n\n### Comment:\n\nFor STM32F4xx microcontrollers, the manual indicates that these devices are intended for use in functional safety applications. However, it doesn't provide specific details about the results of the FIPS 140-2 tests. I couldn't find any specific results related to on the NIST website. Since this standard was released back in 2001, the associated documentation could be found in a large collection on the NIST website / archives.\n\nHere is the output of the Debian **`rngtest`** which implements the FIPS 140-2 tests: [Output](https://github.com/MicroControleurMonde/PyBOARD_RNG/blob/main/Reports/Pyb_RNG_Test_13Mi_rngtest.txt)\n\nThat being said, it's worth noting that STMicroelectronics has currently many other MCU models that are FIPS certified.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicrocontroleurmonde%2Fpyboard_rng","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmicrocontroleurmonde%2Fpyboard_rng","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicrocontroleurmonde%2Fpyboard_rng/lists"}