- 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)
推薦閱讀
- OpenStack Cloud Computing Cookbook(Third Edition)
- .NET之美:.NET關鍵技術深入解析
- LabVIEW程序設計基礎與應用
- C++面向對象程序設計(微課版)
- Visual Basic程序設計教程
- 碼上行動:零基礎學會Python編程(ChatGPT版)
- Functional Kotlin
- HTML5入門經典
- Oracle從入門到精通(第5版)
- Nginx實戰:基于Lua語言的配置、開發與架構詳解
- Swift語言實戰精講
- Getting Started with Eclipse Juno
- GitHub入門與實踐
- Android Development Tools for Eclipse
- Python自然語言理解:自然語言理解系統開發與應用實戰