{"id":21040983,"url":"https://github.com/chfoo/trandom","last_synced_at":"2026-02-08T23:33:01.717Z","repository":{"id":145909887,"uuid":"175711602","full_name":"chfoo/trandom","owner":"chfoo","description":"Cross-platform Haxe library for accessing cryptographic secure numbers ","archived":false,"fork":false,"pushed_at":"2020-01-28T20:10:44.000Z","size":25,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-18T10:08:45.635Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Haxe","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chfoo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2019-03-14T22:49:01.000Z","updated_at":"2025-03-07T09:48:16.000Z","dependencies_parsed_at":"2024-02-13T07:00:29.263Z","dependency_job_id":null,"html_url":"https://github.com/chfoo/trandom","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/chfoo/trandom","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chfoo%2Ftrandom","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chfoo%2Ftrandom/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chfoo%2Ftrandom/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chfoo%2Ftrandom/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chfoo","download_url":"https://codeload.github.com/chfoo/trandom/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chfoo%2Ftrandom/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268629788,"owners_count":24281172,"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","status":"online","status_checked_at":"2025-08-03T02:00:12.545Z","response_time":2577,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-11-19T13:49:33.473Z","updated_at":"2026-02-08T23:32:56.692Z","avatar_url":"https://github.com/chfoo.png","language":"Haxe","readme":"# trandom\n\ntrandom is a cross-platform Haxe library for accessing cryptographic secure numbers from the target's cryptographic random number generator.\n\n## Supported targets\n\n| Target | Source |\n|--------|--------|\n| CPP (C++) | See Sys. Windows: `RtlGenRandom` |\n| CS (C#) | `cs.system.security.cryptography.RandomNumberGenerator` |\n| Flash (SWF) | `flash.crypto.generateRandomBytes` |\n| Hashlink |See Sys. Windows: `RtlGenRandom` |\n| Java | `java.security.SecureRandom` |\n| JS | HTML: `window.crypto`, Nodejs: `crypto.randomBytes` |\n| Lua | See Sys. Windows: not implemented |\n| Neko | See Sys. Windows: `RtlGenRandom` |\n| PHP | `random_int` |\n| Python | `os.urandom` |\n| Sys | Any OS that provides `/dev/urandom`, `/dev/random` |\n\n## Getting started\n\nRequires:\n\n* Haxe 3 or 4\n\n### Install\n\nDownload and install the library using haxelib:\n\n    haxelib install trandom\n\nOr you may install it directly from GitHub:\n\n    haxelib git https://github.com/chfoo/trandom\n\nOr finally for the security minded, you may install from a ZIP file release after verifying its signature:\n\n    haxelib install trandom-X.X.X-20YYmmdd-HHMMSS.zip\n\n### Usage\n\ntrandom only provides one API method:\n\n```haxe\nimport trandom.TargetRandom;\npublic static function random():Int\n```\n\nReturns a signed 32-bit integer from the target's cryptographic secure random number generator.\n\nIf there is no secure source, a String exception is thrown. Other exceptions may be thrown by the underlying target.\n\nDepending on the operating system, this method may block for a long period of time until there is sufficient entropy.\n\n### Example\n\nThe following example shows how to convert the value to a byte array:\n\n```haxe\nimport trandom.TargetRandom;\n\nclass Main {\n    public static function main() {\n        var randomValue = TargetRandom.random();\n        trace(randomValue); // =\u003e Int\n\n        var bytes = haxe.io.Bytes.alloc(4);\n        bytes.setInt32(0, randomValue);\n    }\n}\n```\n\n## Platform notes\n\n### Windows\n\nA macro will automatically add `-D trandom_windows` to the Haxe compiler config. This define will enable the call to RtlGenRandom for targets that don't provide a builtin API to a cryptographic source. It uses the target's foreign function interface system to bind with trandom's native C code. If you don't want this behavior, add `-D trandom_no_auto_ffi`.\n\n#### Hashlink\n\nThe hdll library `trandom.hdll` needs to be included with your application. A prebuilt library is included in the release ZIP file.\n\nTo build it manually using MinGW-w64:\n\n    i686-w64-mingw32-gcc.exe -O -D HASHLINK_DLL_EXPORTS -fPIC -shared -std=c11 -o trandom.hdll trandom_native.c -I hl-1.9.0-win/include\n\nAdjust paths in the command as needed.\n\n#### Neko\n\nThe hdll library `trandom.hdll` needs to be included with your application. A prebuilt library is included in the release ZIP file.\n\nTo build it manually using MinGW-w64:\n\n    i686-w64-mingw32-gcc.exe -O -D NEKOVM_DLL_EXPORTS -fPIC -shared -std=c11 -o trandom.hdll trandom_native.c -I $NEKO_INSTPATH/include -L $NEKO_INSTPATH -lneko\n\nAdjust paths in the command as needed.\n\n#### CPP - MinGW-w64 (Optional)\n\nThe library is statically linked in the hxcpp pipeline, so no `dll` needs to be built. The following is extra information for those who want to use MingGW instead of Visual Studio.\n\nIf you are having trouble getting hxcpp to use Visual Studio for compilation, you can use MingGW-w64.\n\nTo enable compilation by MinGW, add this to `%HOMEPATH%/.hxcpp_config.xml` under the \"VARS\" section:\n\n    \u003cset name=\"mingw\" value=\"1\" /\u003e\n\nIf needed, add the path to MinGW-w64:\n\n    \u003cset name=\"MINGW_ROOT\" value=\"C:\\Program Files (x86)\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\" /\u003e\n\n### Flash\n\nUse `-swf-version 11` or greater version number in your Haxe compiler config to access the Flash crypto package API. The default is 10.0. At the time of writing, the current version is 43.\n\n## Considerations\n\n* Don't fallback to using `Math.random` or `Sys.random` for cryptographic purposes\n* If used in a virtual machine with snapshots, the returned values may be the same\n* The quality of randomness is determined by the target or platform\n* Be aware of DLL injection attacks (for hdll and ndll libraries)\n\n### Alternatives\n\n* Use a libsodium Haxe binding to [randombytes_random()](https://libsodium.gitbook.io/doc/generating_random_data)\n  * libsodium also includes many other cross-platform methods. If you are using trandom for cryptographic purposes, it probably would be easier to use libsodium throughout.\n* On native platforms, you can use [callfunc](https://github.com/chfoo/callfunc) to call libsodium or OS functions directly.\n\n## Contributing\n\nIf you have a bug report or issue, please file an issue. If you would like to fix a bug or implement support for more platforms/targets, please make a pull request.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchfoo%2Ftrandom","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchfoo%2Ftrandom","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchfoo%2Ftrandom/lists"}