Let’s Roll a Die

Let’s say I want to create the ability to roll a die in my program. Without giving it a second thought, we would call the the built-in function Math.random() in JavaScript (or the equivalent in any other language) and tweak it with some simple manipulation to our desired range. But is this number actually random? The dictionary definition of random is described as follows:

“made, done, happening, or chosen without method or conscious decision.”

This is almost the total opposite of what we expect computer programs to be. Computers and programs are by nature procedural and intentionally designed. …

Most of us are familiar with logical operators like && and || and maybe even the bitwise operators & and |. A quick refresher — logical operators utilizes short circuiting to determine the value of the expression while bitwise operators on Integer operates on the individual bits of the Integer in binary.

Logical operators like && and || are special in Ruby in that they behave the same exact way for all objects in Ruby. They behave the same way for Integer , String, Float , Hash etc. You cannot override their functionalities in Ruby. …

One of the fundamental things we are exposed to when we first learn any programming language are logical operators. We can already accomplish a lot with just && (AND) and || (OR) operators. We can use these to check if certain conditions are met or control the flow of our programs. They are small and yet extremely powerful.

We often hear Ruby is a user friendly programming language and strives to be easily understood and as close to spoken English as possible. Then why in the world do we need to type the ampersand (&&) or the pipe (||) twice…

Amy Cen

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store