这是什么线code的意思吗? [英] What does this line of code mean?

查看:187
本文介绍了这是什么线code的意思吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道这行code的意思?

I am wondering what this line of code mean?

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

gren_rand_uniform()是随机生成0和1的数字功能。但是我不明白其中的意思> 0.5 1:0

The gren_rand_uniform() is a function to generate random 0 and 1 numbers. However I don't get the meaning for >0.5 and 1:0.

我知道这应该是一个基本的问题,请多多包涵。

I know this is supposed to be a basic question, please bear with me.

谢谢!

推荐答案

这是速记。在你给的例子,它相当于:

It's shorthand. In the example you gave, it is equivalent to:

if (gen_rand_uniform() > 0.5) {
    b = 1;
} else {
    b = 0;
}

由于 gen_rand_uniform()可能产生均匀 1 之间分布的随机数和 0 ,还有的值是高于0.5的机率为50%。这意味着有获得的50%的几率在 1 0

Since gen_rand_uniform() probably generates uniformly distributed random numbers between 1 and 0, there's a 50% chance of the value being higher than 0.5. Which means there's a 50% chance of getting a 1 or a 0

这篇关于这是什么线code的意思吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆