8 Replies Latest reply on Oct 9, 2007 4:58 PM by jjay@aus

# Randomly Adjusting Numbers

I need to randomly adjust a large setu of number up 1% or down 2% individually.

I did write a script whereby I create a random decimal number between 1 and -2 and multiply the originaly number by the result of the random number, but the minus numbers weren't giving me what I expected (you mathematicians out there are probably chuckling to yourself right now I am sure.. but hey.. I tried :).

Now I am kind of at a loss. Does anyone have any suggestions on how I can randomly adjust a number (e.g.300,000) in a range between 1% increase and 2% decrease?

• ###### 1. Re: Random Decimal Numbers
jjay@aus wrote:
> I am trying to create random, non-integer numbers between -2 and .2.

maybe something like this:

<cfscript>
now=now();
random=createObject("java","java.util.Random").init(now.getTime());
v1=3*random.nextDouble()-2;
v2=3*rand("SHA1PRNG")-2; // cf8
writeoutput("#v1# #v2#");
</cfscript>
• ###### 2. Re: Random Decimal Numbers
jjay@aus wrote:
Does anyone have any suggestions on how I can randomly adjust a number (e.g.300,000) in a range between 1% increase and 2% decrease?

The Coldfusion function rand() returns a real number, that is, a decimal number, between 0 and 1 at random. Therefore, 3*rand() is a random real number between 0 and 3. It follows that 98+3*rand() is a random real number between 98 and 101. Hence, 98+3*rand() is the factor you seek.

However, you have to divide it by 100. For example, a decrease of 2% is equivalent to 98% or 0.98 of the original value. An increase of 1% is equivalent to 101% or 1.01 of the original value. The code follows.

• ###### 3. Re: Random Decimal Numbers
jjay@aus wrote:
> I am trying to create random, non-integer numbers between -2 and .2.

wow you completely edited the content & even the title of this thread. in the
future start a new thread otherwise it's confusing to those of use who use NNTP.

• ###### 4. Re: Random Decimal Numbers
wow! yeah! at first i thought BKBK has gone mad...

strange... i am sure that in the past* all edits to posts came in as new
posts in nntp...

* = before Adobe's attempt at upgrading the forums

--

Sabai-dee.com
http://www.sabai-dee.com
• ###### 5. Re: Randomly Adjusting Numbers
wow! yeah! at first i thought BKBK has gone mad...
I have, as it happens.

• ###### 6. Re: Random Decimal Numbers
> wow! yeah! at first i thought BKBK has gone mad...

no comment.

> strange... i am sure that in the past* all edits to posts came in as new
> posts in nntp...

no i think this has always been the case but this is the 1st time i've noticed
a thread so completely changed....
• ###### 7. Re: Randomly Adjusting Numbers
We could just see it as jjay@aus asking two separate questions. He/She is then the richer.

• ###### 8. Re: Randomly Adjusting Numbers
My Apologies to all those I have confused. I found the answer to my first questions literally minutes after submitting the posting (always the way), I originally came in to submit a reply to that nature and asking the next question found that the entire posting could be edited, and as no-one had responded at that time (had only been up a few minutes) I figured that must be the best way to minimise confusion. On the contrary.. clearly. Apologies again.

Again, apologies for the confusion (I know now), and thanks to those that help.

Cheers