{
  "category": "Math and trigonometry functions",
  "display_name": "RAND",
  "entry_kind": "built_in_function",
  "eval_api": {
    "method": "POST",
    "url": "https://handbook.dnacalc.com/api/eval"
  },
  "function_id": "FUNC.RAND",
  "implementation_state": {
    "answer_bank": null,
    "detail": "Recorded: 2 workbook cells. A volatile function: the recorded formulas hold it fixed, for example RAND()*0, so these cells show that the call works and not a clock or random value.",
    "dnacalc_commit": "9e1884369a678158dd82d3d74188daf986995e87",
    "in_catalogue": true,
    "state": "matches",
    "state_label": "Matches every recorded Excel answer",
    "summary": "Matches all 2 recorded answers",
    "workbook_corpus": {
      "cells": 2,
      "matched": 2
    }
  },
  "implementations": [
    {
      "commit": "9e1884369a678158dd82d3d74188daf986995e87",
      "flavour": "excel-compatibility-candidate",
      "language": "Rust",
      "name": "CalcFunc",
      "own_code": [
        "https://github.com/DnaCalc/DnaCalc/blob/9e1884369a678158dd82d3d74188daf986995e87/crates/calc-func/src/catalogue/random.rs#L32-L35"
      ],
      "repository": "https://github.com/DnaCalc/DnaCalc",
      "shared_code": [
        "catalogue/random::draw"
      ],
      "source": "https://github.com/DnaCalc/DnaCalc/blob/9e1884369a678158dd82d3d74188daf986995e87/crates/calc-func/src/catalogue/random.rs#L32-L35",
      "state": "matches",
      "suite": null,
      "summary": "Matches all 2 recorded answers"
    }
  ],
  "json_url": "https://handbook.dnacalc.com/api/functions/FUNC.RAND.json",
  "name": "RAND",
  "notes": [],
  "schema": "efh.function-reference/v1",
  "section_order": [
    "what-it-does",
    "try-it",
    "quirks",
    "how-to-implement",
    "version-differences",
    "alternatives"
  ],
  "sections": {
    "alternatives": "\n### Relationships\n\n\n- **[RANDBETWEEN](FUNC.RANDBETWEEN.md)** — the integer sampler, built from the same stream, with\n  an inclusive upper bound where `RAND` has an exclusive one. The endpoint difference is the most\n  common source of off-by-one sampling errors in spreadsheets.\n- **[RANDARRAY](FUNC.RANDARRAY.md)** — the dynamic-array generalisation, which subsumes both:\n  `RANDARRAY()` with no arguments is `RAND()`, and `RANDARRAY(1,1,a,b,TRUE)` is\n  `RANDBETWEEN(a,b)`.\n- **`RAND()*(b-a)+a`** — the documented idiom for a uniform draw on `[a, b)`. It inherits `RAND`'s\n  half-open interval, and it loses resolution when `a` and `b` are far apart in magnitude.\n- **`INDEX(range, RANDBETWEEN(1, ROWS(range)))`** — sampling *with* replacement. There is no\n  built-in sampler without replacement; `SORTBY(range, RANDARRAY(ROWS(range)))` is the modern\n  idiom, and it is a permutation only if the draws are distinct.\n- **`NORM.INV(RAND(), μ, σ)`** — the inverse-transform route to a normal deviate, and the place\n  where the quality of `RAND`'s low-order bits and the accuracy of the inverse CDF in the tails\n  both stop being academic.\n\n\n",
    "how-to-implement": "\n### Numerical notes\n\n\n**Resolution.** A generator producing a `[0,1)` double can offer anywhere from 2⁻³² to 2⁻⁵³\nspacing. Two constructions dominate: `k/2⁵³` with `k` a 53-bit integer (uniform on a lattice,\nnever returns exactly 1, can return exactly 0), and `(k+½)/2⁵³` (never returns either endpoint).\nA generator built by dividing a 32-bit integer by 2³² gives only about 4×10⁹ distinct values,\nwhich is visible as ties in any sample of a few hundred thousand rows — the birthday bound bites\naround 65,536 draws. If a workbook's Monte Carlo shows duplicate draws, this is why.\n\n**Period and equidistribution matter more than \"randomness\".** A combined multiplicative\ncongruential generator in the Wichmann–Hill family (AS 183) has a period around 7×10¹² and fails\nmodern spectral tests; a Mersenne Twister has period 2¹⁹⁹³⁷−1 and 623-dimensional\nequidistribution but is not cryptographic and fails linear-complexity tests; a modern counter-based\nor `xoshiro`-family generator does better in less state. For a spreadsheet, the practical\nquestions are (a) how many draws before the sequence repeats, (b) whether consecutive draws are\nindependent when used as coordinates of a point — the classic lattice failure that makes a pair of\n`RAND()` cells trace visible planes in a scatter plot — and (c) whether the low bits are as good\nas the high bits. L'Ecuyer & Simard's TestU01 is the standard instrument for all three.\n\n**Streams and parallelism.** Once a generator is shared across cells, the *assignment of draws to\ncells* becomes part of the answer. The two disciplined solutions are a single serialised stream\n(what `HostSerialized` describes) and per-cell counter-based generation, where the draw is a\nkeyed function of the cell address and a workbook counter — reproducible, parallel-safe, and\ncompatible with nothing that already exists.\n\n**On Excel's actual generator, this page says nothing.** Microsoft has characterised it in\ndifferent terms across versions, and external authors — McCullough & Wilson most persistently —\nhave published critiques of specific releases. The Handbook has not tested any Excel build's\ngenerator and does not restate anyone's account of it. What can be said without evidence is only\nthe contract: half-open, uniform by declaration, volatile.\n\n\n",
    "quirks": "\n### Result and edge cases\n\n\nReturns `Number` in `[0, 1)`.\n\n- **Volatility.** `VolatileFull` means the cell recomputes on every recalculation of the workbook,\n  not only when a precedent changes. A sheet full of `RAND()` re-randomises when you edit an\n  unrelated cell, press F9, or open the file. This is a property of the *engine's* dependency\n  handling, not of the function's mathematics, and it is why a `RAND()` column cannot be used as a\n  stable key.\n- **Thread serialisation.** `HostSerialized` records that the surface cannot be evaluated freely in\n  parallel: a shared stream has to be advanced under a lock, or two threads get the same draw. Any\n  implementation that parallelises recalculation has to decide whether the *sequence* of draws is\n  part of the observable behaviour. If it is, parallel evaluation changes results; if it is not,\n  nothing is reproducible anyway.\n- **Zero is attainable in principle.** The documented interval includes 0, so a formula that\n  divides by `RAND()` has a genuine — if astronomically unlikely, and generator-dependent — failure\n  mode. Whether any real implementation ever emits exactly 0 depends on how the bits are assembled;\n  see the numerical notes.\n\n\n\n### Errors\n\n\nNo documented error condition. Nothing in the argument list can fail, because there is no argument\nlist.\n\n",
    "sources": "- Microsoft, Excel JavaScript API, `Excel.Functions.rand` —\n  <https://learn.microsoft.com/en-us/javascript/api/excel/excel.functions> (the documented range\n  and the \"changes on recalculation\" statement).\n- L'Ecuyer & Simard, \"TestU01\", ACM TOMS 33(4), 2007; Wichmann & Hill, Algorithm AS 183, *Applied\n  Statistics* 31(2), 1982; McCullough & Wilson, *Computational Statistics & Data Analysis*\n  (1999–2008 series on Excel's statistical procedures).\n- Handbook, [The value universe](../model/01-value-universe.md),\n  [Claim language and honesty](../model/06-claim-language.md).\n- Handbook projections `data/functions/FUNC.RAND.json` (`PseudoRandom`, `VolatileFull`,\n  `HostSerialized`, `RandomProvider`, `ApplicationState`) and `data/presence/FUNC.RAND.json` (own\n  module, no shared surfaces, no defect streams).\n\n",
    "version-differences": "No comparison between specific Excel builds is recorded here yet. This does not establish that all builds behave alike.",
    "what-it-does": "\n`RAND()` returns a pseudo-random number in the half-open interval **[0, 1)** — at least zero and\nstrictly less than one — intended to be uniformly distributed, and recomputed on every\nrecalculation.\n\nMicrosoft's Excel JavaScript API reference states the contract in one sentence: \"Returns a random\nnumber greater than or equal to 0 and less than 1, evenly distributed (changes on recalculation).\"\nBoth endpoints matter. The lower end is *attainable* and the upper end is not, which is what makes\n`RAND()*(b-a)+a` a correct sampler for `[a, b)` and `1/RAND()` a formula that can divide by zero.\n\n\n### Arguments\n\n\nNone. Arity is exactly zero and the parentheses are mandatory syntax.\n\nThe absence of a seed argument is the single most consequential design decision on this page:\nthere is no worksheet-level way to reproduce a draw, and therefore no worksheet-level way to make\na model deterministic. Workbooks that need reproducibility freeze values (paste-as-values) or move\nthe generator outside Excel.\n\n\n"
  },
  "signature": {
    "display": "RAND()",
    "parameters": [],
    "trailing_repeats": false
  },
  "sources": {
    "metadata": {
      "admission": {
        "label": "implemented",
        "reason": null
      },
      "arity": {
        "max": 0,
        "min": 0
      },
      "category": "Math and trigonometry functions",
      "classification": {
        "arg_preparation_profile": "ValuesOnlyPreAdapter",
        "coercion_lift_profile": "None",
        "determinism_class": "PseudoRandom",
        "error_collapse_profile": "None",
        "fec_dependency_profile": "RandomProvider",
        "host_interaction_class": "ApplicationState",
        "kernel_signature_class": "Custom",
        "rich_value_usage": "RichBlind",
        "surface_fec_dependency_profile": "RandomProvider",
        "thread_safety_class": "HostSerialized",
        "volatility_class": "VolatileFull"
      },
      "descriptions": {
        "long": null,
        "short": "A random number from 0 up to but not including 1, new at each recalculation",
        "short_source": "dna-calc-own"
      },
      "docs": {
        "english_description": "Returns a random number between 0 and 1",
        "microsoft_url": "https://support.microsoft.com/en-us/office/rand-function-4cbfa695-8869-4788-8d90-021ea9f5be73"
      },
      "entry_kind": "built_in_function",
      "localized_family_names": null,
      "localized_names": [
        {
          "locale": "ar-SA",
          "name": "RAND"
        },
        {
          "locale": "bg-BG",
          "name": "RAND"
        },
        {
          "locale": "cs-CZ",
          "name": "NÁHČÍSLO"
        },
        {
          "locale": "da-DK",
          "name": "SLUMP"
        },
        {
          "locale": "de-DE",
          "name": "RAND"
        },
        {
          "locale": "el-GR",
          "name": "RAND"
        },
        {
          "locale": "en-AU",
          "name": "RAND"
        },
        {
          "locale": "en-GB",
          "name": "RAND"
        },
        {
          "locale": "en-US",
          "name": "RAND"
        },
        {
          "locale": "es-ES",
          "name": "RAND"
        },
        {
          "locale": "et-EE",
          "name": "RAND"
        },
        {
          "locale": "fi-FI",
          "name": "SATUNNAISLUKU"
        },
        {
          "locale": "fr-FR",
          "name": "RAND"
        },
        {
          "locale": "he-IL",
          "name": "RAND"
        },
        {
          "locale": "hr-HR",
          "name": "RAND"
        },
        {
          "locale": "hu-HU",
          "name": "VÉL"
        },
        {
          "locale": "id-ID",
          "name": "RAND"
        },
        {
          "locale": "it-IT",
          "name": "CASUALE"
        },
        {
          "locale": "ja-JP",
          "name": "RAND"
        },
        {
          "locale": "ko-KR",
          "name": "RAND"
        },
        {
          "locale": "lt-LT",
          "name": "RAND"
        },
        {
          "locale": "lv-LV",
          "name": "RAND"
        },
        {
          "locale": "nb-NO",
          "name": "RAND"
        },
        {
          "locale": "nl-NL",
          "name": "RAND"
        },
        {
          "locale": "pl-PL",
          "name": "LOS"
        },
        {
          "locale": "pt-BR",
          "name": "RAND"
        },
        {
          "locale": "pt-PT",
          "name": "ALEATÓRIO"
        },
        {
          "locale": "ro-RO",
          "name": "RAND"
        },
        {
          "locale": "ru-RU",
          "name": "RAND"
        },
        {
          "locale": "sk-SK",
          "name": "RAND"
        },
        {
          "locale": "sl-SI",
          "name": "RAND"
        },
        {
          "locale": "sr-Latn-RS",
          "name": "RAND"
        },
        {
          "locale": "sv-SE",
          "name": "SLUMP"
        },
        {
          "locale": "th-TH",
          "name": "RAND"
        },
        {
          "locale": "tr-TR",
          "name": "=S_SAYI_ÜRET()"
        },
        {
          "locale": "uk-UA",
          "name": "RAND"
        },
        {
          "locale": "vi-VN",
          "name": "RAND"
        },
        {
          "locale": "zh-CN",
          "name": "RAND"
        },
        {
          "locale": "zh-HK",
          "name": "RAND"
        },
        {
          "locale": "zh-TW",
          "name": "RAND"
        }
      ],
      "signature": {
        "display": "RAND()",
        "parameters": [],
        "trailing_repeats": false
      },
      "surface_name": "RAND",
      "version_marker": null,
      "xlcall": {
        "code": "63",
        "symbol": "xlfRand"
      }
    },
    "microsoft": "https://support.microsoft.com/en-us/office/rand-function-4cbfa695-8869-4788-8d90-021ea9f5be73"
  },
  "try_it": {
    "formula": "=RAND()",
    "note": "OneCalc does not supply a random-number source in this preview.",
    "preview_status": "refused"
  },
  "url": "https://handbook.dnacalc.com/functions/RAND.html",
  "variants": [],
  "versions": []
}