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

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)
主站蜘蛛池模板: 山阴县| 阿图什市| 桐乡市| 偃师市| 洪江市| 石屏县| 弥渡县| 永胜县| 门头沟区| 北辰区| 万荣县| 奈曼旗| 肥乡县| 叶城县| 武山县| 都匀市| 敦煌市| 汕头市| 黄冈市| 柳林县| 湘西| 清镇市| 光山县| 故城县| 永川市| 舟山市| 陇川县| 上虞市| 淳安县| 自治县| 沈阳市| 徐水县| 呼玛县| 江永县| 万宁市| 博湖县| 竹北市| 介休市| 荣成市| 光山县| 大悟县|