简体   繁体   中英

Excel Randomize Decimal Number

I found a very nice function in MS Excel 2007 which is RANDBETWEEN(bottom, top) . The problem with this is that it randomize whole number only. Using this formula:

=RANDBETWEEN(7.0, 9.9)

yields

8.0
9.0
7.0
7.0
etc...

How can I modify it so that it will also produce decimal numbers like below

7.5
7.2
9.4
9.5
7.1
8.5
etc...

使用randbetween(70,99)并将结果除以10。

Since RANDBETWEEN() used to be available exclusively in the Analysis ToolPak (and produced a #NAME? error when the ToolPak was not installed ), you might be better off using RAND() for backwards compatibility, multiplying and adding to shift the range and rounding to one decimal place:

=ROUNDUP(7 + RAND() * (9.9 - 7 - 0.1), 1)    ' Excludes 7.0 and 9.9
=ROUNDUP(7 + RAND() * (9.9 - 7), 1)          ' Excludes 7.0, includes 9.9    
=ROUNDDOWN(7 + RAND() * (9.9 - 7), 1)        ' Includes 7.0, excludes 9.9
=ROUNDDOWN(7 + RAND() * (9.9 - 7 + 0.1), 1)  ' Includes 7.0 and 9.9

But the RANDBETWEEN() issue is just a backwards compatibility issue now, so if you're sure your spreadsheet will only be used in Excel 2007 and up, you'll be fine with either approach.

Refer this http://ms-office.wonderhowto.com/how-to/generate-random-numbers-with-decimals-excel-338595/

Random decimal number between 30-40

=rand()*10+30

Random decimal number between 0-100

=rand()*100+0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM