{"id":21948119,"url":"https://github.com/evolution-gaming/random","last_synced_at":"2025-10-14T19:37:47.100Z","repository":{"id":43320981,"uuid":"174215876","full_name":"evolution-gaming/random","owner":"evolution-gaming","description":"Pure random number generator","archived":false,"fork":false,"pushed_at":"2025-08-27T10:02:35.000Z","size":165,"stargazers_count":4,"open_issues_count":9,"forks_count":3,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-10-14T19:37:45.799Z","etag":null,"topics":["cats","random","rng","scala"],"latest_commit_sha":null,"homepage":null,"language":"Scala","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/evolution-gaming.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2019-03-06T20:27:51.000Z","updated_at":"2025-08-27T10:02:40.000Z","dependencies_parsed_at":"2024-09-12T01:15:15.297Z","dependency_job_id":"288bf1b6-d742-45e1-bab4-c905613ca529","html_url":"https://github.com/evolution-gaming/random","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"purl":"pkg:github/evolution-gaming/random","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evolution-gaming%2Frandom","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evolution-gaming%2Frandom/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evolution-gaming%2Frandom/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evolution-gaming%2Frandom/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/evolution-gaming","download_url":"https://codeload.github.com/evolution-gaming/random/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evolution-gaming%2Frandom/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279020657,"owners_count":26086898,"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-10-14T02:00:06.444Z","response_time":60,"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":["cats","random","rng","scala"],"created_at":"2024-11-29T05:12:05.491Z","updated_at":"2025-10-14T19:37:47.081Z","avatar_url":"https://github.com/evolution-gaming.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Random\n[![Build Status](https://github.com/evolution-gaming/random/workflows/CI/badge.svg)](https://github.com/evolution-gaming/random/actions?query=workflow%3ACI)\n[![Coverage Status](https://coveralls.io/repos/evolution-gaming/random/badge.svg)](https://coveralls.io/r/evolution-gaming/random)\n[![Codacy Badge](https://app.codacy.com/project/badge/Grade/20c2455aa4e14e8a85b362f3e508383d)](https://app.codacy.com/gh/evolution-gaming/random/dashboard?utm_source=gh\u0026utm_medium=referral\u0026utm_content=\u0026utm_campaign=Badge_grade)\n[![Artifactory](https://img.shields.io/github/v/release/evolution-gaming/random)](https://evolution.jfrog.io/ui/packages/gav:%2F%2Fcom.evolution:random_2.13)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellowgreen.svg)](https://opensource.org/licenses/MIT)\n\nPure deterministic pseudo-random number generator, which returns a new state on each call.\nThe returned state could be used to generate a next random value, without\nrelying for it to be saved in a mutable variable inside of the RNG library.\n\nIt could be useful for writing the code, when the direct usage of an effect\nsystem such as `cats.effect.IO` is either not possible or not desired. Also,\nthe versions `0.1.1` and below are compatible with Cats Effect 2.\n\nIf the application already uses Cats Effect 3 and pure random generator is not\nrequired then https://typelevel.org/cats-effect/docs/std/random might be a\npreferred choice for sake of using a more standard solution.\n\n```scala\ntrait Random[F[_]] {\n\n  def int: F[Int]\n\n  def long: F[Long]\n\n  def float: F[Float]\n\n  def double: F[Double]\n}\n```\n\n## Setup\n\n```scala\naddSbtPlugin(\"com.evolution\" % \"sbt-artifactory-plugin\" % \"0.0.2\")\n\nlibraryDependencies += \"com.evolution\" %% \"random\" % \"1.0.5\"\n```\n\n## Usage\n\nThe library could be used directly with pure Scala without any additional effect systems:\n```scala\ndef currentTimeSeedExample(): Unit = {\n  // note, that current time could be a bad choice for a seed\n  val state0 = Random.State(System.currentTimeMillis())\n  val (state1, n0) = state0.int\n  val (_, n1) = state1.int\n  println(s\"Two random numbers: $n0, $n1\")\n}\n```\n\nIt also includes facilities to create a random number generator with a safe seed based on the current time from Cats Effect `Clock` instance:\n```scala\ndef clockSeedExample: IO[Unit] =\n  for {\n    state0 \u003c- Random.State.fromClock[IO]()\n    (state1, n0) = state0.int\n    (_, n1) = state1.int\n    _ \u003c- IO.println(s\"Two random numbers: $n0, $n1\")\n  } yield ()\n```\n\nThe typical Cats Effect user might prefer storing these instances in `IOLocal`\nfor efficiency and code readability (i.e. to not pass a state manually around):\n\n``` scala\ndef ioLocalExample: IO[Unit] =\n  for {\n    random \u003c- IOLocalRandom.fromClock\n    n0 \u003c- random.int\n    n1 \u003c- random.int\n    _ \u003c- IO.println(s\"Two random numbers: $n0, $n1\")\n  } yield ()\n  \nobject IOLocalRandom {\n\n  def fromClock: IO[Random[IO]] =\n    for {\n      random \u003c- Random.State.fromClock[IO]()\n      random \u003c- IOLocal(random)\n    } yield new Random[IO] {\n      def int: IO[Int] = random.modify(_.int)\n      def long: IO[Long] = random.modify(_.long)\n      def float: IO[Float] = random.modify(_.float)\n      def double: IO[Double] = random.modify(_.double)\n    }\n\n}\n```\n\nIt is also possible to use the same approach in a Tagless Final environment\nusing `ThreadLocalOf` from Cats Helper library:\n\n```scala\nimport com.evolutiongaming.catshelper.ThreadLocalOf\n\ndef threadLocalExample[F[_]: Monad: Clock: Console: ThreadLocalOf]: F[Unit] =\n  for {\n    random \u003c- ThreadLocalRandom.fromClock[F]\n    n0 \u003c- random.int\n    n1 \u003c- random.int\n    _ \u003c- Console[F].println(s\"Two random numbers: $n0, $n1\")\n  } yield ()\n\nobject ThreadLocalRandom {\n\n  def fromClock[F[_]: Monad: Clock: ThreadLocalOf]: F[Random[F]] =\n    for {\n      random \u003c- Random.State.fromClock[F]()\n      random \u003c- ThreadLocalOf[F].apply(random)\n    } yield new Random[F] {\n      def int: F[Int] = random.modify(_.int)\n      def long: F[Long] = random.modify(_.long)\n      def float: F[Float] = random.modify(_.float)\n      def double: F[Double] = random.modify(_.double)\n    }\n\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevolution-gaming%2Frandom","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fevolution-gaming%2Frandom","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevolution-gaming%2Frandom/lists"}