{"id":15722623,"url":"https://github.com/selimanac/defold-random","last_synced_at":"2025-04-15T22:50:44.765Z","repository":{"id":152789738,"uuid":"179742400","full_name":"selimanac/defold-random","owner":"selimanac","description":"PCG Random Number Generator Native Extension for the Defold Game Engine","archived":false,"fork":false,"pushed_at":"2024-07-08T11:43:21.000Z","size":127,"stargazers_count":29,"open_issues_count":0,"forks_count":0,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-29T02:12:09.583Z","etag":null,"topics":["defold","defold-game-engine","defold-library","pcg","random-number-generators"],"latest_commit_sha":null,"homepage":"https://selimanac.github.io/","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/selimanac.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":"selimanac"}},"created_at":"2019-04-05T19:26:31.000Z","updated_at":"2025-01-28T11:10:02.000Z","dependencies_parsed_at":"2024-10-24T16:51:02.773Z","dependency_job_id":"d5637ba1-86cf-48ce-8b8f-c9254c952143","html_url":"https://github.com/selimanac/defold-random","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/selimanac%2Fdefold-random","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/selimanac%2Fdefold-random/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/selimanac%2Fdefold-random/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/selimanac%2Fdefold-random/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/selimanac","download_url":"https://codeload.github.com/selimanac/defold-random/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249167434,"owners_count":21223505,"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":["defold","defold-game-engine","defold-library","pcg","random-number-generators"],"created_at":"2024-10-03T22:08:39.825Z","updated_at":"2025-04-15T22:50:44.738Z","avatar_url":"https://github.com/selimanac.png","language":"C","funding_links":["https://github.com/sponsors/selimanac"],"categories":["Libraries"],"sub_categories":["Programming Language"],"readme":"![Defold - PCG Random](/.github/pcgrandom-hero.png?raw=true)\n\n# Defold - PCG Random\n\nPCG Random Number Generator Native Extension for the Defold Game Engine\n\nThis extension allow you to generate random numbers using minimal [C implementation of PCG](http://www.pcg-random.org/using-pcg-c-basic.html).\n\nIt uses [entropy](https://github.com/imneme/pcg-c/blob/master/extras/entropy.c) seed internally with fallback to time based seed. You can switch to Time based seed and remove the entropy by uncommenting/commenting a few lines on the source code, but I don't think it is necessary. \n\n## Installation\nYou can use PCG Random in your own project by adding this project as a [Defold library dependency](http://www.defold.com/manuals/libraries/). Open your game.project file and in the dependencies field under project add:\n\n\thttps://github.com/selimanac/defold-random/archive/master.zip\n\t\n---\n\n## Toss a Coin to Your Witcher\nIf you find my [Defold Extensions](https://github.com/selimanac) useful for your projects, please consider [supporting](https://github.com/sponsors/selimanac) it.  \nI'd love to hear about your projects! Please share your released projects that use my native extensions. It would be very motivating for me.\n\n\n\n## Usage\n\n### rnd.seed(`init_state`, `init_seq`)\n\nSeeds the random number generator.   \nRandom number generator is always initialized by using entropy seed. You don't need to call this method unless you want to control the seed.\n\n\n`init_state` is the starting state for the RNG, you can pass any 64-bit value.  \n`init_seq` selects the output sequence for the RNG, you can pass any 64-bit value, although only the low 63 bits are significant.\n \n**Caution:** I don't recommend using of 64-bit integers. Consider using 32-bit integers instead. \n\n### rnd.seed()\n\nRe-seed the random number generator by using entropy seed.  \nRandom number generator is always initialized by using entropy seed. You don’t need to call this method unless you want to re-seed.\n\n### rnd.number()\n\nReturns a 32 bit unsigned integer.\n\n### rnd.range(`min`, `max`)\n\nReturns a 32 bit unsigned integer between min and max values. Only for positive numbers(unsigned integers).   \nSame as **math.random(3,20)**  \n**math.random(90)** == rnd.range(1, 90)\n\n### rnd.double()\n\nReturns a floating point between 0-1.  \nSame as **math.random()**\n\n### rnd.double_range(`min`, `max`)\n\nReturns a floating point between min - max.  \nNot fast as `rnd.double()`\n\n### rnd.dice(`roll`, `type`)\n\nDnD style dice roller.   \n\n**PARAMETERS**\n\n* ```roll``` (int) - Roll amount\n* ```type``` (enum) - Type of the dice\n\n\t**rnd.d4** : D4: four-sided die.       \n\t**rnd.d6** : D6: six-sided die.    \n\t**rnd.d8** : D8: eight-sided die.    \n\t**rnd.d10** : D10: ten-sided die (0-9).   \n\t**rnd.d12** : D12: twelve-sided die.    \n\t**rnd.d20** : D20: twenty-sided die.    \n\t**rnd.d100** : D%: percentile die (0-90).    \n\t\n**RETURN**\n\n* ```result``` (table) - Dice results\n* ```total``` (int) - Total amout of dice results\n\n**EXAMPLE**\n\n```lua\n\nlocal result, total = rnd.dice(2, rnd.d10)\n\n```\n\n\n### rnd.toss()\n\nToss a coin. Returns 0 or 1 (0 = 'H', 1 = 'T')\n\n### rnd.roll()\n\nRoll the dice. Returns between 1-6\n\n### rnd.check()\n\nTesting entropy.\n\n\n\n## Release Notes\n\n1.2.7\n\n- rnd.dice added. \n\n1.2.6\n\n- Fix for [#6](https://github.com/selimanac/defold-random/issues/6#issue-951284950)\n- Fix for [#7](https://github.com/selimanac/defold-random/issues/7#issue-951982666)\n- Auto-complete for native extensions \n\n1.2.5\n\n- Fix for [#4](https://github.com/selimanac/defold-random/issues/4#issue-837151758)\n\n1.2.4\n\n- `rnd.double_range(min, max)` added.\n\n1.2.3\n\n- `rnd.range` returns min if min == max.\n\n1.2.2\n\n- `rnd.range` was causing a crash when MIN is bigger than MAX. Error message added.\n\n1.2.1\n\n- Added static seed\n- Small fix.\n\n1.1\n\n- Fixed integers.\n\n1.0\n\nInitial release.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fselimanac%2Fdefold-random","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fselimanac%2Fdefold-random","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fselimanac%2Fdefold-random/lists"}