boolean

The Dart ternary operator syntax (examples) alvin September 21, 2019 - 2:48pm

As a quick note, the Dart ternary operator syntax is the same as the Java ternary operator syntax. The general syntax is:

result = testCondition ? trueValue : falseValue

A few examples helps to demonstrate Dart’s ternary syntax:

A Java method that returns a random boolean value based on a probability

If you ever need a Java method that returns a boolean value based on a given probability, I can confirm that this method works:

/**
 * `probability` should be given as a percentage, such as
 * 10.0 (10.0%) or 25.5 (25.5%). As an example, if `probability` 
 * is 60% (60.0), 100 calls to this function should return ~60 
 * `true` values.
 * (Note that Math.random returns a value >= 0.0 and < 1.0.)
 */
static boolean getRandomBoolean(float probability) {
    double randomValue = Math.random()*100;  //0.0 to 99.9
    return randomValue <= probability;
}
Boolean algebra was named after George Boole alvin October 28, 2017 - 1:37pm

Boolean algebra was named after George Boole (1815-1864), which I just learned while reading A Book of Abstract Algebra.

A simple Java Random class example alvin September 28, 2009 - 12:00am

As I was digging around through some code today, I found the following Java Random class example, and thought I'd share it here for anyone needed to see how to work with the Random class in Java. This example shows how to generate a random number in Java that is greater than or equal to 0, and less than 100:

Ant FAQ: How to determine the platform operating system in an Ant build script

Problem

You're creating an Ant build script, and you need to determine the operating system the script is running on, so you can make conditional decisions within the build script. You typically want/need to do this if you're going to run tasks/targets that are different for each operating system (Mac, Windows, Unix, etc.).

How to make a conditional decision in an Ant build script based on operating system alvin July 5, 2009 - 6:57pm

Background

I was writing with a former co-worker the other day about how to do some things that are specific to Mac OS X in his Java Swing applications (see How to make a Java/Swing application look like a native Mac OS X application), but also keep his Ant build script working on a Windows computer.

Perl ‘equals’ FAQ: What is true and false in Perl? alvin October 10, 2008 - 3:47pm

Perl true/false FAQ: What is true in Perl? What is false in Perl?

The Perl programming language is a little unusual in not having true and false boolean operators. Because of this, I can never seem to remember what equates to true and false in Perl, so I decided to create this page.

What is true/false in Perl

In short, the following elements evalue to false in Perl:

AppleScript tip: working with booleans alvin November 9, 2007 - 3:41pm

It's easy to work with boolean (true/false) variables in AppleScript. Here's an example of how you assign a boolean to a variable: