Generating random -1 and +1 values in Excel

2019-06-17 07:16发布

问题:

The Rand() function would generate a real number between 0 and 1. The Randbetween(-1,1) would generate either -1, 0, or 1. What I want is only -1 or 1. And what about real numbers between -1 and 1?

回答1:

Easy:

=IF(RAND()<0.5,-1,1)

To get the real numbers, use

=RAND()*2-1



回答2:

Here is a solution:

=Randbetween(0,1)*2-1


回答3:

You can use RANDBETWEEN to generate two values, either 0 or 1, and substitute -1 for 0.

=IF(RANDBETWEEN(0,1) = 0, -1, 1)


回答4:

do rand, if it is more than .5, return 1, if it is less, return -1

=IF(RAND()>0.5,1,-1)


标签: excel random