Operator Overloading in Java

C++ has operator overloading. Java does not. Java folks just say the operation overloading is really bad, that it provides bad abstraction and leads to very unreliable and difficult to manage code. That’s why Java doesn’t have operators overloading.

Random String in PostgreSQL

Last time I wrote about common problem with the random function. PostgreSQL has only the random(). There is no function like random(from, to) or random(length), which returns a random text of the given length.

This time I just needed a function which returns a random text of the given length. Then it can be used like this: SELECT random_text(42). The random text will be used as a slug in a web application, so I need only numbers and letters and let’s also have only uppercase.

Let’s create a PL/pgSQL procedure for returning a random text with the given length.

Common Problem with random(min, max)

There is a common problem with many homemade random functions. All languages which I know have some kind of random() function. This function returns a floating point number within the range [0.0, 1.0) with uniform distribution of values.

The random generators can have different distribution of the values, but in this entry I will just write about the uniformly distributed generator.