Skip to content

SampleRandom

Narta Xaymar Dirks edited this page Dec 2, 2026 · 1 revision

SampleRandom BlitzLLVM

SampleRandom:Float32 random:Int32, from:Float32=0, to:Float32=1
Parameter Mode Type Default Description
random In Int32 required The generator.
from In Float32 0 Lowest result. Defaults to 0 for a Float or Double.
to In Float32 1 Highest result (an Int) or the bound that the result stays below (a Float or Double). Defaults to 1 for a Float or Double.

Returns: A random number of the type that the call asks for.

Description

BlitzLLVM This command does not exist in the original Blitz products. BlitzLLVM adds it.

A random number from a generator of CreateRandom, from from to to. The type of the number is the one the call asks for with its suffix, so one command gives every kind:

Call Gives
SampleRandom%(rng, from, to) An Int from from to to, both included. Every number in the range is equally likely and every one can come up, however big the range is: SampleRandom(rng, 0, 1000000) gives any of the 1,000,001 numbers, where Rand only has 65,536 different results, and SampleRandom(rng, -2147483647 - 1, 2147483647) gives any Int.
SampleRandom#(rng, from, to) A Float from from up to to, not including to. It uses all 24 bits that a Float has, where Rnd only has 16.
SampleRandom:Double(rng, from, to) A Double from from up to to, not including to, with all 53 bits that a Double has, from two numbers of the generator.
  • Without a suffix, the bounds decide, as they do for an operator: two Ints give an Int, a Float gives a Float and a Double gives a Double. So SampleRandom(rng, 0, 1) is 0 or 1, and SampleRandom(rng, 0.0, 1.0) a Float.
  • Without bounds, it is a Float (or a Double with :Double) from 0 up to 1. An Int always needs its bounds, and one bound alone is refused.
  • The bounds can be given in either order.
  • The same seed gives the same numbers on every system.
  • A generator with the Blitz engine (3) gives what Rand gives for an Int and what Rnd gives for a Float, 16 bits and all, and its Doubles only have those 16 bits too.

Differences

  • Not in the originals.

Examples

rng = CreateRandom(0, 7)
For i = 1 To 3
	Print SampleRandom(rng, 1, 6)
Next
f# = SampleRandom(rng)
Print f >= 0 And f < 1
angle# = SampleRandom#(rng, 0, 360)
Print angle >= 0 And angle < 360
d:Double = SampleRandom:Double(rng, 1000000, 2000000)
Print d >= 1000000 And d < 2000000
2
6
3
1
1
1

Related Commands

CreateRandom BlitzLLVM, FreeRandom BlitzLLVM, RandomState BlitzLLVM, SeedRandom BlitzLLVM, SetRandomState BlitzLLVM

Home · Command Index


Getting started

Language

Tools


Language Features
BlitzBasic
Blitz3D
BlitzPlus
Differences

More

Clone this wiki locally