RAND function with categories

  • Thread starter Thread starter benny
  • Start date Start date
B

benny

Hi..it seems so simple but i couldn't make it.
What RAND function I should applied if I want to generate some randoms value
between 100 and 1000.

Many thanks and much appreciate for help.
 
benny said:
Hi..it seems so simple but i couldn't make it.
What RAND function I should applied if I want to generate some randoms
value
between 100 and 1000.

Many thanks and much appreciate for help.

Hi Benny,

Rand() yields numbers between 0 and 1. You can transform this interval with
the following formula (abs cuts off the fractional part):

Abs(Rand() *900 +100)

or generally

Abs(Rand() * (UpperBound - LowerBound) + LowerBound)

cheers,
Stephan
 
Hi Benny,

Rand() yields numbers between 0 and 1. You can transform this interval
with the following formula (abs cuts off the fractional part):

Abs(Rand() *900 +100)

or generally

Abs(Rand() * (UpperBound - LowerBound) + LowerBound)

cheers,
Stephan

Sorry Stephan, you said correct but you wrote wrong:

Int(Rand() * (UpperBound - LowerBound) + LowerBound)

Ciao
Bruno
 
Bruno Campanini said:
Sorry Stephan, you said correct but you wrote wrong:

Int(Rand() * (UpperBound - LowerBound) + LowerBound)

Ciao
Bruno

so true, Int(...) is the way to go. Thanks for the correction. Just tried it
now and VBA does not like/know Rand(). It's called Rnd().

Stephan
 
The formula to return random numbers between 2 set points is:

=RAND()*(b-a)+a

Where a = minimum limit
And b = maximum limit

So, for your question, use this formula:
=RAND()*900+100

To eliminate the decimals, you can Round() the formula:
=ROUND(RAND()*900+100,0)

The formula changes slightly if you truncate the decimal using Int():
=INT(RAND()*901+100)

This change insures that the maximum limit has the *possibility* of being
returned.
--

HTH,

RD
=====================================================
Please keep all correspondence within the Group, so all may benefit!
=====================================================

Hi..it seems so simple but i couldn't make it.
What RAND function I should applied if I want to generate some randoms value
between 100 and 1000.

Many thanks and much appreciate for help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top