Random String The Easy Way

- https://github.com/vinkla/laravel-hashids
- http://stackoverflow.com/questions/4407161/find-duplicate-strings-in-database

function rndmHash()
  // get the current time in nanosecond 
  // to make sure the duplication margin is small
  // then hash it
  $string = system('date +%s%N');
  $hash   = Hashids::encode($string);

  // incase "Hashids" failed
  return $hash !== '' ? $hash : uniqid();

foreach ($x as $y) {
  // ...

  // get a new random on each iteration
  $name = rndmHash();

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.