Generate a random number: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
m (Updated author links.) |
|||
(4 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
{{PageAuthor|Afrow UK}} | |||
== Description == | == Description == | ||
This is a simple script to generate a number between 0 and 9. | This is a simple script to generate a number between 0 and 9. | ||
Line 36: | Line 34: | ||
</highlight-nsis> | </highlight-nsis> | ||
== The Function v2 == | |||
<highlight-nsis> | |||
Function GenRanNum | |||
Push $R0 | |||
GetTempFileName $R0 | |||
Delete $R0 | |||
StrCpy $R0 $R0 1 -5 | |||
IntFmt $R0 "%u" 0x$R0 | |||
StrCpy $R0 $R0 "" -1 | |||
Exch $R0 | |||
FunctionEnd | |||
</highlight-nsis> | |||
== Example == | |||
[[User:Afrow UK|Afrow UK]] used this to generate random BrandingImages for placing on the side of my installer during the installation process. | |||
You can use the value generated like so: | You can use the value generated like so: | ||
Line 58: | Line 71: | ||
-Stu | -Stu | ||
[[Category:Math Functions]] |
Latest revision as of 19:42, 11 October 2015
Author: Afrow UK (talk, contrib) |
Description
This is a simple script to generate a number between 0 and 9.
Usage
Call GenRanNum Pop $R0
The Function
Function GenRanNum Push $R0 Push $R1 Push $R2 GetTempFileName $R0 GetFileTime $R0 $R1 $R2 StrLen $R1 $R2 StrCpy $R1 $R2 1 -$R1 StrCmp $R1 - 0 +5 StrLen $R1 $R2 IntOp $R1 $R1 - 1 StrCpy $R2 $R2 1 -$R1 Goto +2 StrCpy $R2 $R1 Delete $R0 StrCpy $R0 $R2 Pop $R2 Pop $R1 Exch $R0 FunctionEnd
The Function v2
Function GenRanNum Push $R0 GetTempFileName $R0 Delete $R0 StrCpy $R0 $R0 1 -5 IntFmt $R0 "%u" 0x$R0 StrCpy $R0 $R0 "" -1 Exch $R0 FunctionEnd
Example
Afrow UK used this to generate random BrandingImages for placing on the side of my installer during the installation process.
You can use the value generated like so:
IntCmp $R2 2 0 0 +3 SetBrandingImage "$TEMP\ddayupdates\left_logo1.bmp" Goto set_bitmap_end IntCmp $R2 5 0 0 +3 SetBrandingImage "$TEMP\ddayupdates\left_logo2.bmp" Goto set_bitmap_end IntCmp $R2 7 0 0 +3 SetBrandingImage "$TEMP\ddayupdates\left_logo3.bmp" Goto set_bitmap_end SetBrandingImage "$TEMP\ddayupdates\left_logo4.bmp" set_bitmap_end:
-Stu