funnymango
funnymango

Reputation: 31

Random.value to bool?

This Minesweeper Tutorial uses Random.value to convert to bool:

mine = Random.value < 0.15;

Can anyone explain how this works? As far as I understand is that Random.value returns a float. How does it convert to bool there and why is it followed by > 0.15?

Upvotes: 1

Views: 3247

Answers (1)

Selman Gen&#231;
Selman Gen&#231;

Reputation: 101701

The condition Random.value < 0.15 returns a boolean value, it returns true if Random.value is less than 0.15, false otherwise. Then that value is assigned to mine.

More generally, Random.value < 0.15 is a boolean expression that uses less than < Operator.And each boolean expression evalutes to either true or false.

Upvotes: 10

Related Questions