{"id":16614566,"url":"https://github.com/0tickpulse/coupon-simulator","last_synced_at":"2026-04-24T09:36:11.747Z","repository":{"id":195154462,"uuid":"692363131","full_name":"0tickpulse/coupon-simulator","owner":"0tickpulse","description":null,"archived":false,"fork":false,"pushed_at":"2023-09-16T08:58:09.000Z","size":2,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-18T00:44:45.087Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","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/0tickpulse.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":"2023-09-16T08:50:48.000Z","updated_at":"2023-09-16T08:50:54.000Z","dependencies_parsed_at":null,"dependency_job_id":"81fc4313-5355-4a9c-b907-449a9f50ed3a","html_url":"https://github.com/0tickpulse/coupon-simulator","commit_stats":{"total_commits":3,"total_committers":2,"mean_commits":1.5,"dds":"0.33333333333333337","last_synced_commit":"189e446651a427b68415f542218394f978dad410"},"previous_names":["0tickpulse/coupon-simulator"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/0tickpulse/coupon-simulator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0tickpulse%2Fcoupon-simulator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0tickpulse%2Fcoupon-simulator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0tickpulse%2Fcoupon-simulator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0tickpulse%2Fcoupon-simulator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/0tickpulse","download_url":"https://codeload.github.com/0tickpulse/coupon-simulator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0tickpulse%2Fcoupon-simulator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32217032,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-24T08:24:32.376Z","status":"ssl_error","status_checked_at":"2026-04-24T08:24:26.731Z","response_time":64,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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-10-12T02:06:54.503Z","updated_at":"2026-04-24T09:36:06.719Z","avatar_url":"https://github.com/0tickpulse.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Coupon Simulator\n\nThis is a simulation of the famous [coupon collector's problem](https://en.wikipedia.org/wiki/Coupon_collector%27s_problem). The problem is as follows:\n\n\u003e Given a set of $n$ coupons, each with a unique number, how many coupons do you need to draw with replacement until you have drawn each coupon at least once?\n\nThe answer is $nH_n$, where $H_n$ is the $n$ th [harmonic number](https://en.wikipedia.org/wiki/Harmonic_number). This simulation will run the experiment for a given number of coupons and write the average number of draws to the standard output.\n\n## Usage\n\n```bash\ncargo run\n```\n\n## Explanation\n\nThe mathematical simulation lies in the trial function. The function creates an array called `collected`, which has `N` elements, each being `false`. Each element in this array represents whether that element has been collected. While any of the elements are `false`, it will keep generating a random number between 0 and `N` and setting the corresponding element in `collected` to `true`. Once all elements are `true`, it will return the number of draws it took to collect all coupons, completing one trial of the simulation.\n\nThe rest of the program is just a loop that creates a few threads and runs the trial function in each thread. It then takes the average of the results and prints it to the standard output.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0tickpulse%2Fcoupon-simulator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F0tickpulse%2Fcoupon-simulator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0tickpulse%2Fcoupon-simulator/lists"}