- Perl 6 Deep Dive
- Andrew Shitov
- 159字
- 2021-07-03 00:05:53
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)
推薦閱讀
- 手機安全和可信應用開發指南:TrustZone與OP-TEE技術詳解
- Learning Python Web Penetration Testing
- Python自然語言處理實戰:核心技術與算法
- Practical Internet of Things Security
- Spring Boot+Spring Cloud+Vue+Element項目實戰:手把手教你開發權限管理系統
- INSTANT MinGW Starter
- 數據結構簡明教程(第2版)微課版
- oreilly精品圖書:軟件開發者路線圖叢書(共8冊)
- Visual Basic程序設計
- Solr Cookbook(Third Edition)
- PHP與MySQL權威指南
- 分布式架構原理與實踐
- 零基礎C#學習筆記
- JSP應用與開發技術(第3版)
- LibGDX Game Development By Example