Roll Dice With Get-Random

Simulate one or more dice rolls with a cryptographically seeded RNG.

WindowsrandomscriptingpowershellLow risk
Run Get-Random -Minimum 1 -Maximum 7 to roll a single six-sided die.

01Command

Command
$ Get-Random -Minimum 1 -Maximum 7

02What it does

Get-Random returns a random value; the upper bound is exclusive, so Maximum 7 yields 1 through 6. Pipe a range into it or loop to roll several dice, for example 1..2 | ForEach-Object { Get-Random -Minimum 1 -Maximum 7 }.

03Risk

RiskLow risk
RequirementsWindows 10/11 with PowerShell 5.1 or PowerShell 7+
!Warning: For security-sensitive randomness use -SetSeed never; the default already uses a strong generator, but avoid predictable seeds.

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

  • Get-Random
    Microsoft Learn · vendor-doc · 2026-09-20
    Evidence: Documents -Minimum/-Maximum ranges and collection selection.

Last verified: 2026-09-20 · Category: Developer

06Related solutions