This is very similar and just another way to do it. It should work but may need to be tweaked.
Global TotalSprites% = 0 Const maxsprites% = 40 IF TimeToSpawn = True and TotalSprites% < maxsprites% THEN IF TotalSprites% <= (maxsprites% - 5) THEN tmp% = Rnd(1,5) SpawnSprites(tmp%) TotalSprites% = TotalSprites% + tmp% ELSE tmp% = Rnd(1, maxsprites% - TotalSprites%) SpawnSprites(tmp%) TotalSprites% = TotalSprites% + tmp% ENDIF ENDIF