NsRandom plug-in: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Moved some text and corrected nsRandom's name.)
m (NsRandom moved to NsRandom plug-in)

Revision as of 14:48, 3 December 2005

Author: lzandman (talk, contrib)


Links

NsRandom.zip (20 KB)
Zip.gif nsRandom.zip (20 KB) (Author's mirror)

Description

nsRandom is a NSIS-plugin created by Leon Zandman that can generate random numbers.

Usage

nsRandom is a plugin wrapper around Borland Delphi's Random() function. It can generate random numbers in two ways:

  • Range-mode
  • Float-mode

Range-mode

In this mode nsRandom generates a random number x in the following range: 0 ≤ x < Range, where Range is a positive number that has been pushed onto the stack. See the following example:

; Use random number from range: 0 <= Random < 100
; Put range onto the stack
Push "100"
 
; Get the random number
nsRandom::GetRandom

; Take the generated number from the stack
Pop $2

Float-mode

In this mode nsRandom generates a random number x in the range 0 ≤ x < 1. You can activate this mode by putting a negative value for Range onto the stack. See the following example:

; Put a negative range value onto the stack (=float-mode)
Push "-1"
 
; Get the random number
nsRandom::GetRandom

; Take the generated number from the stack
Pop $2

Note

nsRandom was created after some discussion in this forum thread.