Generate a random number: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Wikipedia python library)
 
m (Updated author and download links, and changed format of some pages.)
Line 55: Line 55:
-Stu
-Stu


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

Revision as of 12:38, 23 April 2005

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

Page author: Afrow UK