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

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)
主站蜘蛛池模板: 平定县| 开原市| 东源县| 大邑县| 高邑县| 驻马店市| 临西县| 汤原县| 遂平县| 阆中市| 阳江市| 木兰县| 来凤县| 新昌县| 浦东新区| 龙江县| 迁安市| 刚察县| 华宁县| 铜梁县| 虹口区| 彭水| 色达县| 双桥区| 卢氏县| 克什克腾旗| 古丈县| 光山县| 嘉祥县| 张家港市| 阿合奇县| 新兴县| 峨山| 江北区| 体育| 辉南县| 五峰| 佛冈县| 岚皋县| 晋州市| 大余县|