{"record":{"id":"edc3832e23bac44d","repo":"jax-ml/jax","slug":"prng-key-seed-must-be-an-integer-got-seed-r-edc383","errorCode":null,"errorMessage":"PRNG key seed must be an integer; got {seed!r}","messagePattern":"PRNG key seed must be an integer; got (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/random/philox4x32.py","lineNumber":154,"sourceCode":"  \"\"\"Return True if key is a Philox 4x32 key.\"\"\"\n  try:\n    return key.shape == (2,) and key.dtype == np.uint32\n  except AttributeError:\n    return False\n\n\ndef philox4x32_seed(seed: typing.Array) -> typing.Array:\n  \"\"\"Create a single Philox 4x32 PRNG key from an integer seed.\"\"\"\n  return _philox4x32_seed(seed)\n\n\n@api.jit(inline=True)\ndef _philox4x32_seed(seed: typing.Array) -> typing.Array:\n  \"\"\"Internal implementation of philox4x32_seed.\"\"\"\n  if seed.shape:\n    raise TypeError(f\"PRNG key seed must be a scalar; got {seed!r}.\")\n  if not np.issubdtype(seed.dtype, np.integer):\n    raise TypeError(f\"PRNG key seed must be an integer; got {seed!r}\")\n  convert = lambda k: lax.convert_element_type(k, np.uint32)\n  k0 = convert(\n      lax.shift_right_logical(seed, lax.convert_element_type(32, seed.dtype))\n  )\n  with config.numpy_dtype_promotion(\"standard\"):\n    k1 = convert(jnp.bitwise_and(seed, np.uint32(0xFFFFFFFF)))\n  # Hash through philox4x32 to mix the seed bits into a 2-word key.\n  # Use the seed halves as counter words so both influence the output.\n  out = philox4x32_p.bind(\n      np.uint32(0),\n      np.uint32(0),\n      k0,\n      k1,\n      np.uint32(0),\n      np.uint32(0),\n  )\n  return jnp.array([out[0], out[1]], dtype=np.uint32)\n","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/random/philox4x32.py#L136-L172","documentation":"philox4x32_seed requires the seed to have an integer dtype; float, complex, or bool seeds raise this TypeError because the seed is decomposed into 32-bit integer words.","triggerScenarios":"Calling philox4x32_seed(jnp.float32(0.0)) or PRNGKey with a float seed under the philox4x32 implementation.","commonSituations":"Float seeds from configuration files or time.time(); np.bool_ seeds from flags.","solutions":["Convert to int first: int(seed), np.int64(seed), or jnp.asarray(seed, jnp.uint32)","Canonicalize seed handling in one helper that coerces to int"],"exampleFix":"# before\nkey = philox4x32_seed(jnp.array(1.5))\n# after\nkey = philox4x32_seed(jnp.array(1, dtype=np.uint32))","handlingStrategy":"validation","validationCode":"import numpy as np\nif not np.issubdtype(np.asarray(seed).dtype, np.integer):\n    seed = int(seed)","typeGuard":"def is_integer_seed(seed) -> bool:\n    import numpy as np\n    return np.issubdtype(np.asarray(seed).dtype, np.integer)","tryCatchPattern":null,"preventionTips":["Keep seeds integral end-to-end in configs","Cast float-loaded seeds with int(round(x))"],"tags":["jax","prng","seed","dtype-validation"],"backgroundTag":"prng-seed-validation","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}