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

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)
主站蜘蛛池模板: 浠水县| 奈曼旗| 绥化市| 苍山县| 嘉鱼县| 南乐县| 乌拉特前旗| 东山县| 南雄市| 自治县| 碌曲县| 贵德县| 阜康市| 乌什县| 获嘉县| 原阳县| 宜宾市| 枣强县| 肥东县| 中阳县| 盐源县| 宁强县| 正定县| 祁连县| 通许县| 上犹县| 新丰县| 高台县| 安福县| 苏州市| 安国市| 鄂托克旗| 曲周县| 新绛县| 沁水县| 宿州市| 枞阳县| 滁州市| 浦县| 马鞍山市| 潮州市|