Mohammad Syed
Mohammad Syed

Reputation: 23

How to exclude 0 when using RandBetween?

Essentially, I want to have a random + or - so I'm using a RandBetween(-1,1). However, when the value is value is zero, I obviously get the same number I started off with. Is there a way to exclude the zero?

Thanks in advance!

Excel Example: =J1+(J1*RAND()*RANDBETWEEN(-1,1)*0.1)

Upvotes: 0

Views: 2323

Answers (2)

John Coleman
John Coleman

Reputation: 51998

For fun, here is a different solution which uses RandBetween:

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

Upvotes: 2

user2285236
user2285236

Reputation:

This will select 1 or -1 with 50% probability:

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

Upvotes: 3

Related Questions