• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Randomly Adjusting Numbers

New Here ,
Oct 08, 2007 Oct 08, 2007

Copy link to clipboard

Copied

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?

Thanks in advance.
TOPICS
Advanced techniques

Views

525

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Oct 08, 2007 Oct 08, 2007
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 o...

Votes

Translate

Translate
LEGEND ,
Oct 08, 2007 Oct 08, 2007

Copy link to clipboard

Copied

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 08, 2007 Oct 08, 2007

Copy link to clipboard

Copied

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.


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 09, 2007 Oct 09, 2007

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 09, 2007 Oct 09, 2007

Copy link to clipboard

Copied

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

--

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 09, 2007 Oct 09, 2007

Copy link to clipboard

Copied

wow! yeah! at first i thought BKBK has gone mad...
I have, as it happens.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 09, 2007 Oct 09, 2007

Copy link to clipboard

Copied

Azadi wrote:
> 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....

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 09, 2007 Oct 09, 2007

Copy link to clipboard

Copied

We could just see it as jjay@aus asking two separate questions. He/She is then the richer.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 09, 2007 Oct 09, 2007

Copy link to clipboard

Copied

LATEST
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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation