You probably should use some basic math for this.
35/40 is 0.875... your ratio basically.
Then set sprite.width to 40 + random(X)
and in the following action you set sprite.height to sprite.width*0.875.
That should work. Remember you will not really get random sizes this way since you're only adding a random number to the size. You should use + random(X) - random(X) or something. Unless you want only bigger versions of course.