Generate a random number: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Updated author and download links, and changed format of some pages.)
m (Updated author links.)
Line 1: Line 1:
{|align=right
|<small>Author: [[{{ns:2}}:Afrow UK|Afrow UK]] ([[{{ns:3}}:Afrow UK|talk]], [[{{ns:-1}}:Contributions/Afrow UK|contrib]])</small>
|}
<br style="clear:both;">
== 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 54: Line 58:


-Stu
-Stu
Page author: [[User:Afrow UK|Afrow UK]]

Revision as of 02:57, 30 April 2005

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

I 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