What does this line of code mean?

后端 未结 7 1020
抹茶落季
抹茶落季 2021-01-21 04:39

I am wondering what this line of code mean?

b = (gen_rand_uniform()>0.5)?1:0;

The gren_rand_uniform() is a function to generate

7条回答
  •  礼貌的吻别
    2021-01-21 05:23

    Conditional assignment:

    variable = condition ? value_if_true : value_if_false;
    

    which is equal to:

    if (condition) {
        variable = value_if_true;
    } else {
        variable = value_if_false;
    }
    

    The code you give us is just random bool. It will return either 1 or 0.

提交回复
热议问题