Add or subtract random percentage

I have a whole number (integer) and want to subtract (or add) a random percentage (say, 25-50% for example) to/from it. I’m blanking on how to do this, how would I do it?

dim x as integer
dim r as new random
x=1000 ' or whatever value
x=x-((r.inrange(25,50)/100)*x)

Keep in mind that you’ll still end up with an integer at the end. If that’s not what you want, you’ll need to convert it to a double.

How do I get a random percentage of an integer (not adding or subtracting, but just obtaining a random percentage of a number and assigning that to a variable)? I do want an integer in the end.

Theres is not a great deal of difference between ‘a random percentage of an integer’ and ‘a random number from 0 to the vaue of the integer’

Dave’s code is more or less the answer, but if you want to get a random value that is more than zero and less than original , you need to work out the upper and lower parts of the range first.

[code]dim original as integer = 200 //whatever
Dim lwbound , unbound as integer
dim lowpc , highpc as double
dim pcvalue as integer
dim r as new random

lowpc = 25 //whatever
highpc = 50

lwbound = lowpc/original * 100
highbound = highpc/original/100

//now get a value which lies between the low percentage and high percentage
//you can decide if you want to add or subtract later

pcvalue = r.inrange(lwbound, highbound)[/code]