NsRandom plug-in: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
(Added mirror link and removed my e-mail address)
m (I no longer mirror my plugins)
 
(3 intermediate revisions by 2 users not shown)
Line 4: Line 4:


<attach>NsRandom.zip</attach><br>
<attach>NsRandom.zip</attach><br>
[[Image:Zip.gif]] [http://www.wirwar.com/NSIS/NsRandom.zip NsRandom.zip] (20 KB) (Author's mirror)


== Description ==
== Description ==


nsRandom is a NSIS-plugin created by Leon Zandman that can generate random numbers. This was created after some discussion in [http://forums.winamp.com/showthread.php?s=&threadid=136688 this] forum thread.
nsRandom is a NSIS-plugin created by Leon Zandman that can generate random numbers.


== Usage ==
== Usage ==
Line 19: Line 18:
=== Range-mode ===
=== Range-mode ===


In this mode nsRandom generates random numbers in the following range: 0 &le; Random &lt; ''Range'', where ''Range'' is a positive number that has been pushed onto the stack. See the following example:
In this mode nsRandom generates a random number ''x'' in the following range: 0 &le; ''x'' &lt; ''Range'', where ''Range'' is a positive number that has been pushed onto the stack. See the following example:
<highlight-nsis>
<highlight-nsis>
; Use random number from range: 0 &lt;= Random &lt; 100
; Use random number from range: 0 <= Random < 100
; Put range onto the stack
; Put range onto the stack
Push "100"
Push "100"
Line 34: Line 33:
=== Float-mode ===
=== Float-mode ===


In this mode nsRandom generates random values lying between 0 and 1. You can activate this mode by putting a negative value for ''Range'' onto the stack. See the following example:
In this mode nsRandom generates a random number ''x'' in the range 0 &le; ''x'' &lt; 1. You can activate this mode by putting a negative value for ''Range'' onto the stack. See the following example:
<highlight-nsis>
<highlight-nsis>
; Put negative range onto the stack (=float-mode)
; Put a negative range value onto the stack (=float-mode)
Push "-1"
Push "-1"


Line 45: Line 44:
Pop $2
Pop $2
</highlight-nsis>
</highlight-nsis>
== Note ==
nsRandom was created after some discussion in [http://forums.winamp.com/showthread.php?s=&threadid=136688 this] forum thread.


[[Category:Plugins]]
[[Category:Plugins]]

Latest revision as of 21:08, 28 November 2008

Author: lzandman (talk, contrib)


Links

NsRandom.zip (20 KB)

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.