Archive: Random Number Generation? Here's How!


Random Number Generation? Here's How!
So I am using SuperPiMP to custom intall Gnucleus and it works like a charm! Now, I needed to create a random default nickname for IRC chat, and I wanted the form user12345, of course with the last five digits random. Problem, I couldn't find a random number generator in PiMP and I'm too lazy to create my own.

Solution, I used $HWNDPARENT. I figgure this should be good enough for me, and at least on XP it gives 7 to 8 digit numbers that don't seem to have any pattern to them. To make sure the number was only 5 digits long I used StrCpy $1 $HWNDPARENT 5 and cut the last few digits off.

Now I needed a second random number to generate an alternative nick. I could have just added 1 to the number or even doubled the number to get a new one, but I decided to use the last five numbers of $HWNDPARENT with the following code:

        StrLen $2 $HWNDPARENT
IntOp $2 $2 - 5
StrCpy $2 $HWNDPARENT 5 $2
The two variables are then written to the InstallOptions ini file and displayed in text boxes that the user can edit. Once the text box is closed the values are written the to program's ini. That's everything.

If you have any questions or suggestions on making this easier, let me know =)

Matt Janssen
Decorah, Iowa, USA
matt@mattjanssen.net

http://nsis.sourceforge.net/wiki/Gen..._random_number

http://nsis.sourceforge.net/wiki/Random