官术网_书友最值得收藏!

Methods to generate random Boolean values

There are two methods, pick and roll, both of which can be called with or without the argument. These methods must be called on the class name itself, not on the value of it or a variable.

When either pick or roll is called with no argument, they return a random value, either True or False. We can see that in the following code snippet:

say Bool.pick;
say Bool.roll;

When the methods are called with an integer argument, a list of random values is generated. The integer argument defines the number of elements in the list, but on top of that, the pick method adds its limitation and returns only unique values, which, in the case of the Bool class, is not more than two. Compare the results of the similar calls, as follows:

say Bool.pick(4); # (False True) or (True False)
say Bool.roll(4); # e.g. (False True False False)
主站蜘蛛池模板: 贵南县| 九江县| 绵竹市| 马公市| 商丘市| 乐昌市| 泰宁县| 正镶白旗| 二连浩特市| 叶城县| 宣恩县| 同江市| 通江县| 疏勒县| 泰州市| 宁陕县| 沈阳市| 阳新县| 垣曲县| 济宁市| 静海县| 汾西县| 鄄城县| 威远县| 肇庆市| 台江县| 托里县| 略阳县| 肥乡县| 报价| 林西县| 鞍山市| 巩留县| 漯河市| 兖州市| 报价| 四会市| 张家口市| 隆德县| 色达县| 微博|