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

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)
主站蜘蛛池模板: 涡阳县| 利川市| 太仓市| 乌什县| 壤塘县| 肇庆市| 巢湖市| 鄂伦春自治旗| 明光市| 云和县| 大兴区| 西林县| 杨浦区| 松原市| 宁津县| 合水县| 邢台市| 康定县| 阿拉善盟| 隆子县| 金乡县| 金湖县| 县级市| 呼伦贝尔市| 隆回县| 张掖市| 太保市| 东乌珠穆沁旗| 佛冈县| 清镇市| 游戏| 博野县| 准格尔旗| 孟州市| 衡山县| 远安县| 淮南市| 奈曼旗| 北票市| 山阴县| 平罗县|