{"id":23902689,"url":"https://github.com/mtumilowicz/java11-birthday-paradox","last_synced_at":"2026-06-23T09:31:52.817Z","repository":{"id":110876597,"uuid":"157898581","full_name":"mtumilowicz/java11-birthday-paradox","owner":"mtumilowicz","description":"Simulation of birthday paradox.","archived":false,"fork":false,"pushed_at":"2018-11-16T19:55:42.000Z","size":61,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-23T10:44:21.901Z","etag":null,"topics":["birthday-paradox","simulation"],"latest_commit_sha":null,"homepage":"","language":"Java","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/mtumilowicz.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}},"created_at":"2018-11-16T17:12:23.000Z","updated_at":"2020-01-27T13:28:05.000Z","dependencies_parsed_at":"2023-03-13T13:47:40.432Z","dependency_job_id":null,"html_url":"https://github.com/mtumilowicz/java11-birthday-paradox","commit_stats":{"total_commits":13,"total_committers":1,"mean_commits":13.0,"dds":0.0,"last_synced_commit":"51b4a902e91b2a52063dd5af672e7bd14f7540ec"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mtumilowicz/java11-birthday-paradox","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtumilowicz%2Fjava11-birthday-paradox","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtumilowicz%2Fjava11-birthday-paradox/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtumilowicz%2Fjava11-birthday-paradox/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtumilowicz%2Fjava11-birthday-paradox/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mtumilowicz","download_url":"https://codeload.github.com/mtumilowicz/java11-birthday-paradox/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtumilowicz%2Fjava11-birthday-paradox/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34684673,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-23T02:00:07.161Z","response_time":65,"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":["birthday-paradox","simulation"],"created_at":"2025-01-04T22:49:55.355Z","updated_at":"2026-06-23T09:31:52.800Z","avatar_url":"https://github.com/mtumilowicz.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.com/mtumilowicz/java11-birthday-paradox.svg?branch=master)](https://travis-ci.com/mtumilowicz/java11-birthday-paradox)\n\n# java11-birthday-paradox\nSimulation of birthday paradox.\n\n_Reference_: https://en.wikipedia.org/wiki/Birthday_problem\n\n# definition\nAssumption - year has 365 days.\n\nIn probability theory, the birthday problem or birthday paradox concerns \nthe probability that, in a set of n randomly chosen people, some pair of \nthem will have the same birthday.\n\nInteresting conclusions (based on the assumption that each day of the year \nis equally probable for a birthday):\n* `99.9%` probability is reached with just 70 people\n* `50%` probability with 23 people. \n\n# proof\n* `50%` probability with 23 people. \n    * A - at least two people have the same birthday\n    * A' - no two people have the same birthday\n    \n    `P(A) = 1 - P(A')`\n    \n    So, for n = 23, we have equation:\n    \n    `P(A') = 365 / 365 * 364 / 365 * 363 / 365 * ... * 343 / 365 ~ 0,492703`\n    \n    So `P(A) \u003e 0,5`\n* `99.9%` probability is reached with just 70 people\n    * same reasoning as above\n# simulation\n```\nvar n = ...;\nvar persons = ...;\ndouble haveSameBirthday = ...;\n\nfor (int i = 0; i \u003c n; i++) {\n    if (!StreamDistinctElementsChecker.check(BirthdaySimulator.birthdays(persons))) {\n        haveSameBirthday++;\n    }\n}\n\nvar probability = haveSameBirthday / n;\n```\n* `BirthdaySimulator.birthdays(persons)` generates IntStream with size `persons` \nand range `[1..365]`\n* `StreamDistinctElementsChecker.check(intStream)` checks if given `intStream`\nhas all distinct elements (in a quite interesting way)\n    ```\n    static boolean check(IntStream ints) {\n        return ObjectUtils.defaultIfNull(ints, IntStream.empty())\n                .allMatch(new HashSet\u003c\u003e()::add);\n    }    \n    ```\n\n# tests\nDuring tests we are using https://en.wikipedia.org/wiki/Central_limit_theorem\n\nIn a class `SimulationTest`:\n* `probabilityOf22`\n    ```\n    assertThat(probability, lessThan(0.5));\n    ```\n* `probabilityOf23`\n    ```\n    assertThat(probability, greaterThan(0.5));\n    ```\n* `probabilityOf70`\n    ```\n    assertThat(probability, greaterThan(0.99));\n    ```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmtumilowicz%2Fjava11-birthday-paradox","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmtumilowicz%2Fjava11-birthday-paradox","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmtumilowicz%2Fjava11-birthday-paradox/lists"}