public function bytes($len) {
    /* Code inspired by this blogpost by Enrico Zimuel
     * http://www.zimuel.it/en/strong-cryptography-in-php/ */
    $strong = false;
    if(function_exists('openssl_random_pseudo_bytes')) {
      $rnd = openssl_random_pseudo_bytes($len, $strong);
      if($strong === true) {
        return $rnd;
      }
    }

    /* Either we dont have the OpenSSL library or the data returned was not
     * considered secure. Fall back on this less secure code. */
    if(function_exists('mcrypt_create_iv')) {
      $rnd = mcrypt_create_iv($len, MCRYPT_DEV_URANDOM);
      return $rnd;
    }

    /* Either we dont have the MCrypt library and OpenSSL library or the data returned was not
     * considered secure. Fall back on this less secure code. */
    $rnd = '';
    for ($i=0;$i<$len;$i++) {
      $sha = hash('sha256', mt_rand());
      $char = mt_rand(0,30);
      $rnd .= chr(hexdec($sha[$char].$sha[$char+1]));
    }
    return (binary) $rnd;
  }