randomizer code

1. Senior Member
Join Date
Dec 1969
Posts
486

## randomizer code

I&#039;m working with some randomizer code. Is there a way that a single value is not bigger then 15? Here is the code....<BR><BR>This is an example of the output that I&#039;m getting.<BR><BR>72 <BR>4 <BR>14 <BR>1 <BR>1 <BR>1 <BR>1 <BR>1 <BR>1 <BR>1 <BR>1 <BR>1 <BR>1 <BR><BR><BR>Dim aNumbers(12)<BR>Dim iCnt, _<BR> iRandomNumber, _<BR> iTotalRandom, _<BR> iMaxRandom<BR>Dim sMsg<BR><BR>Randomize Timer<BR><BR>iTotalRandom = 0<BR><BR>For iCnt = 0 To UBound(aNumbers) - 1<BR> iMaxRandom = 100 - (UBound(aNumbers) - iCnt) - iTotalRandom<BR><BR> iRandomNumber = Int((iMaxRandom - 1 + 1) * Rnd + 1)<BR><BR> &#039; MsgBox "iCnt = " & iCnt & vbCrLf & _<BR> "iMaxRandom = " & iMaxRandom & vbCrLf & _<BR> "iRandomNumber = " & iRandomNumber & vbCrLf & _<BR> "iTotalRandom = " & iTotalRandom & vbCrLf<BR><BR> aNumbers(iCnt) = iRandomNumber<BR> iTotalRandom = iTotalRandom + iRandomNumber<BR>Next<BR><BR>aNumbers(UBound(aNumb ers)) = 100 - iTotalRandom<BR><BR>sMsg = "Processing Total = " & iTotalRandom & vbCrLf<BR>iTotalRandom = 0<BR>IRange = 3<BR>For iCnt = 0 To UBound(aNumbers)<BR> iTotalRandom = iTotalRandom + aNumbers(iCnt)<BR> <BR> <BR> <BR> sMsg = sMsg & iCnt & " = " & aNumbers(iCnt) & " (" & iTotalRandom & ")" & vbCrLf<BR> Sheets("Sheet1").Range("F" & IRange).Value = aNumbers(iCnt)<BR> IRange = IRange + 1<BR>Next<BR>sMsg = sMsg & "Final Total = " & iTotalRandom & vbCrLf<BR><BR>MsgBox sMsg<BR><BR>Thanks,

2. Senior Member
Join Date
Dec 1969
Posts
19,082

## RE: randomizer code

hardly advanced. IIRC this is explained in the VBScript documentation<BR><BR>http://msdn.microsoft.com/scripting/<BR><BR><BR>j<BR>http://rtfm.atrax.co.uk/

3. Senior Member
Join Date
Dec 1969
Posts
486

## RE: randomizer code

Can you narrow down the search just a bit for me?<BR><BR>Thanks,

4. Senior Member
Join Date
Dec 1969
Posts
19,082

## RE: randomizer code

&#062; Can you narrow down the search just a bit for me?<BR><BR>sure. get the downloadable docs (you&#039;ll need them in the future I guarantee) and use the index to look for &#039;randomize&#039;

5. Senior Member
Join Date
Dec 1969
Posts
486

## RE: randomizer code

Thanks. You were right this wasn&#039;t advance. I was trying to use the variables instead I hardcoded the value...<BR><BR>&#039;iRandomNumber = Int((iMaxRandom - 1 + 1) * Rnd + 1)<BR> iRandomNumber = CInt(Int((15 * Rnd()) + 1)) <BR><BR>Thanks again,

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•