Javascript: Random Pattern Generator