NsRandom plug-in: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Added category links.)
m (Updated by user: lzandman (talk, contrib).)
Line 4: Line 4:
<br style="clear:both;">
<br style="clear:both;">
== Links ==
== Links ==
<attach>NsRandom.zip</attach><br>
<attach>NsRandom.zip</attach><br>
[[Image:Zip.gif]] [http://home.studenten.net/~wowleon/nsRandom.zip <strike>NsRandom.zip</strike>] (20 KB) (Mirror #1)
[[Image:Zip.gif]] [http://home.studenten.net/~wowleon/nsRandom.zip <strike>NsRandom.zip</strike>] (20 KB) (Mirror #1)


== Description ==
== Description ==
nsRandom is a NSIS-plugin created by [mailto:leon@wirwar.com?subject=nsRandom Leon Zandman] that can generate random numbers.
 
nsRandom is a NSIS-plugin created by [mailto:leon@wirwar.com?subject=nsRandom 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.


== Usage ==
== Usage ==
nsRandom is a plugin wrapper around Borland Delphi's Random() function. It can generate random numbers in two ways:
nsRandom is a plugin wrapper around Borland Delphi's Random() function. It can generate random numbers in two ways:
<ul>*Range-mode*Float-mode</ul>
 
'''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:
*Range-mode
<highlight-nsis>; Use random number from range: 0 &lt;= Random &lt; 100
*Float-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:
<highlight-nsis>
; Use random number from range: 0 &lt;= Random &lt; 100
; Put range onto the stack
; Put range onto the stack
Push "100"
Push "100"
Line 22: Line 31:


; Take the generated number from the stack
; Take the generated number from the stack
Pop $2</highlight-nsis>'''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:
Pop $2
<highlight-nsis>; Put negative range onto the stack (=float-mode)
</highlight-nsis>
 
=== 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:
<highlight-nsis>
; Put negative range onto the stack (=float-mode)
Push "-1"
Push "-1"


Line 30: Line 45:


; Take the generated number from the stack
; Take the generated number from the stack
Pop $2</highlight-nsis>The distribution includes an example NSIS-script file that should explain how this plugin works.
Pop $2
 
</highlight-nsis>
nsRandom was created after some discussion in [http://forums.winamp.com/showthread.php?s=&threadid=136688 this] forum thread.


[[{{ns:14}}:Plugins]]
[[{{ns:14}}:Plugins]]

Revision as of 22:56, 11 June 2005

Author: lzandman (talk, contrib)


Links

NsRandom.zip (20 KB)
Zip.gif NsRandom.zip (20 KB) (Mirror #1)

Description

nsRandom is a NSIS-plugin created by Leon Zandman that can generate random numbers. This was created after some discussion in this forum thread.

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 random numbers in the following range: 0 ≤ Random < Range, where Range is a positive number that has been pushed onto the stack. See the following example:

; Use random number from range: 0 &lt;= Random &lt; 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 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:

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

; Take the generated number from the stack
Pop $2