Posts

Showing posts from March, 2020

Pseudorandom number generators

It's a well-known programming fact that computers do exactly and only what you tell them to do ( ignoring, possibly, the incidence of cosmic rays ).  This fact makes it impossible for a computer to produce a truly random number since, given a program's particular starting state and inputs, the computer will always produce the same output - so if one were to know the starting state and inputs one would always be able to predict the output state.  Truly random processes cannot be predicted in this way. Despite this, computers are used constantly to produce "random" behavior, from online poker websites to monte carlo simulators to photo screensavers that always show the wrong photo at the wrong time.  To generate these to-human-eyes-random effects, programmers use what are known as pseudorandom number generators , which algorithmically produce numbers which are hard to predict if you do not know the initial inputs (known as seeds). One of the best and most well-know...

Ding!

The last time I used a typewriter was when I was a freshman in college.  I found an old typewriter in the library and used it to write letters to my cousin.  A fair amount of letters on the thing didn't work and I never remembered to send those letters - both fitting symbols for the place of the typewriter in modern society.  But, like that typewriter that probably still hangs out in a dingy corner of the library, the mechanico-social conventions surrounding typewriters also limp on: enter the bell alert. Try copy and pasting either of these bits of code into a new program file and running it in your console: ring-a-ding.rb puts `clear` puts "Press enter to ring the bell!" x = "" while x != "bye" x = gets . chomp puts " \a " end bellz.js let i = 0 while ( i < 5 ){ console . log ( ' \u0007 ' ) i ++ } Music! (...well, sound at least) The Ruby escape character "\a" and the Uni...

Things I Don't Like About Ruby Pt. 1

Part one of what I am sure is a long series of things I don't like about Ruby/Rails. Application of natural language features One of things people generally hate about programming is that computers do exactly what you tell them to do.  They don't make decisions, they don't try to guess your mind, they don't just give it a go if they're not sure what your code means.  They just do whatever they're told to do - or, more often, they just error out after you forget to put in a closing bracket. While it's frustrating knowing that one small mistake can ruin your whole program's day, I find a lot of comfort in knowing that my program is doing exactly what I tell it to do, because if it's not working all I have to do is figure out what the right thing to say is.  It's difficult sometimes but it's straightforward. That is, until you start using Rails or ActiveRecord.  Whoever wrote these frameworks decided that as not just as a matter of c...