Repository navigation
Rnd
Home › Mathematical Functions › Rnd
Returns a random Double from 0 up to but not including 1.
Declare Function Rnd ( ByVal seed As Single = 1.0 ) As Doubleseedseed
Returns a number of type Double in the range [0, 1) (i.e. 0 <= Rnd < 1), based on a random seed (see Randomize).
Rnd can use a variety of different algorithms - see Randomize for details of the default and selectable algorithms.
Rnd will return the same sequence of numbers every time a program is run. This sequence can be changed by reseeding the generator.
Note:
Rnd is thread-safe (by using an internal mutex), but not thread specific. Used in the context of a multi-threaded program, only the execution speed is significantly slowed down compared to a single thread call context.
Unfinished structures for other random number generators are also available in the standard header "fbprng.bi".
Returns the random number generated.
result = Rnd( seed )
The default algorithm used depends on the current dialect in use:
- None, if compiled in the -lang qb dialect. Other dialects can also use the same seeding and generating algorithms by calling
Randomizewith the appropriate parameter. For the non-QB-compatible algorithms, if the optional argument is less than 0, it has the same meaning as passing an argument of 1.
'' Function to a random number in the range [first, last), or {first <= x < last}.
Function rnd_range (first As Double, last As Double) As Double
Function = Rnd * (last - first) + first
End Function
'' seed the random number generator, so the sequence is not the same each time
Randomize
'' prints a random number in the range [0, 1), or {0 <= x < 1}.
Print Rnd
'' prints a random number in the range [0, 10), or {0 <= x < 10}.
Print Rnd * 10
'' prints a random integral number in the range [1, 10], or {1 <= n <= 10}.
'' (because: 0 <= Rnd * 10 < 10)
Print Int(Rnd * 10) + 1
'' prints a random integral number in the range [69, 420], or {69 <= n <= 420}.
'' (because: 69 <= rnd_range(69, 421) < 421)
Print Int(rnd_range(69, 421))Category: Mathematical Functions
Kind: function
Reproduced from the FreeBASIC Wiki Manual under the GNU Free Documentation License 1.3 — with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts. Copyright © the FreeBASIC project and wiki contributors. See License.
tiko-lang · Home · Feature Index · Keyword Index · License
FreeBASIC manual pages reproduced under the GNU FDL 1.3.
- Home
- What Is tiko-lang
- Quick Start
- Installing on macOS
- Debugging
- Feature Index
- Compatibility
- FAQ
- AI Cheatsheet
- Generics
- Interfaces
- For Each
- Iterators
- Tuples
- Array Results
- Defer
- Lambdas
- Block Strings
- Partial Types
- String Slices
- Embed
- Typed Variadics
- C Header Import
- Foreign Library Linking
- UString
- Fixed-Width Types
- Nullptr
- String Library
- Format
- Array
- Map
- Set
- LinkedList
- OrderedMap
- OrderedSet
- Sorting
- Optional
- Result
- Smart Pointers
- Date and Time (Chrono)
- Time Zones
- Filesystem
- File Streams
- Config (INI and TOML)
- Codec
- Hash
- UUID
- OS
- Process
- Net
- HTTP and TLS
- Math Library
- Finance
- Logging
- Terminal TUI Library
- PsControls
- tkControls
- sys/win
- Goroutines and Channels
- LLVM Backend
- tiko build
- TIKO_COMPILER
- Variable Declarations
- Standard Data Types
- User Defined Types
- Procedures
- Operators
- Control Flow Statements
- Converting Data Types
- Array Functions
- String Functions
- Mathematical Functions
- Bit Manipulation
- Date and Time Functions
- File I/O Functions
- Console Functions
- User Input (Runtime Library)
- User Input Functions (Graphics Library)
- Screen Functions
- 2D Drawing Functions
- Graphics Library Reference
- Graphics Keyword List
- Memory Functions
- Threading Support Functions
- Error Handling Functions
- Operating System Functions
- Preprocessor
- Intrinsic Defines
- Miscellaneous Keywords
- Modularizing