Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Options to generate small, kind of unique, human-readable tokens (like "V0cM9tnV") ?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Thibaut Barrère  
View profile  
 More options Dec 29 2008, 4:44 am
Newsgroups: comp.lang.ruby
From: Thibaut Barrère <thibaut.barr...@gmail.com>
Date: Mon, 29 Dec 2008 18:44:38 +0900
Local: Mon, Dec 29 2008 4:44 am
Subject: Options to generate small, kind of unique, human-readable tokens (like "V0cM9tnV") ?
Hi,

I'm pretty sure there is a number of options to achieve this, so I'm
asking here. I often need to generate small unique tokens (like for
invitation codes or unimportant authentication token).

In the past I've been using Digest::SHA1.hexdigest(some string) which
gives us something like "d2b7882fa08bb6de8dca62f16298683bfe4f0738".
It's not very user friendly though, and definitely not small.

More recently I've been using ActiveSupport::SecureRandom.base64(6)
which generates "Xst7JGF6" or "zXxWY/Y/", but sometimes it contains
non-url friendly characters like "/".

What do you use ? Is there a specific gem to achieve this in a robust
fashion (= making collisions unlikely, and specify the characters to
be used, like mixture of numbers and characters for instance ?)

cheers and thanks for your input,

Thibaut
--
http://blog.logeek.fr
http://evolvingworker.com


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jamie Macey  
View profile  
 More options Dec 29 2008, 7:19 am
Newsgroups: comp.lang.ruby
From: Jamie Macey <jamie.ma...@gmail.com>
Date: Mon, 29 Dec 2008 21:19:45 +0900
Local: Mon, Dec 29 2008 7:19 am
Subject: Re: Options to generate small, kind of unique, human-readable tokens (like "V0cM9tnV") ?
On Dec 29, 4:44 am, Thibaut Barrère <thibaut.barr...@gmail.com> wrote:

> Hi,

> I'm pretty sure there is a number of options to achieve this, so I'm
> asking here. I often need to generate small unique tokens (like for
> invitation codes or unimportant authentication token).

> In the past I've been using Digest::SHA1.hexdigest(some string) which
> gives us something like "d2b7882fa08bb6de8dca62f16298683bfe4f0738".
> It's not very user friendly though, and definitely not small.

I've mostly just used a substring on SHA1 - hexdigest[8...16] is small
enough to be usable, but still pseudo-random enough for temporary
tokens to not be guessable.

> More recently I've been using ActiveSupport::SecureRandom.base64(6)
> which generates "Xst7JGF6" or "zXxWY/Y/", but sometimes it contains
> non-url friendly characters like "/".

Base64 is A-Za-z0-9/-.  Gsub / for _ and you're pretty url friendly.

> What do you use ? Is there a specific gem to achieve this in a robust
> fashion (= making collisions unlikely, and specify the characters to
> be used, like mixture of numbers and characters for instance ?)

Lastly, not terribly robust, but functional:

  chars = ['A'..'Z', 'a'..'z', '0'..'9'].map{|r|r.to_a}.flatten
  Array.new(6).map{chars[rand(chars.size)]}

--
Jamie


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ryan Davis  
View profile  
 More options Dec 29 2008, 7:51 pm
From: Ryan Davis <ryand-r...@zenspider.com>
Date: Tue, 30 Dec 2008 09:51:11 +0900
Local: Mon, Dec 29 2008 7:51 pm
Subject: Re: Options to generate small, kind of unique, human-readable tokens (like "V0cM9tnV") ?

On Dec 29, 2008, at 01:44 , Thibaut Barrère wrote:

> In the past I've been using Digest::SHA1.hexdigest(some string) which
> gives us something like "d2b7882fa08bb6de8dca62f16298683bfe4f0738".
> It's not very user friendly though, and definitely not small.

I personally think the following is really cute:

> words = File.read("/usr/share/dict/words").split
> max = words.size
> puts "#{words[rand(max)]}-#{words[rand(max)]}"

and can generate 55194924096 different very readable combinations.  
I'll leave it to you to actually make them unique rather than random  
picks.

Eric pointed me to "bubble babble" which ships in digest and makes the  
hash values more readable. It converts your "Xst7JGF6" into "xikal-
fytif-ladog-locef-kixox".

> require 'digest/bubblebabble'
> puts Digest.bubblebabble("Xst7JGF6")

I had no idea that existed... pretty neat.

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John Mettraux  
View profile  
 More options Dec 29 2008, 8:07 pm
From: "John Mettraux" <jmettr...@openwfe.org>
Date: Tue, 30 Dec 2008 10:07:26 +0900
Local: Mon, Dec 29 2008 8:07 pm
Subject: Re: Options to generate small, kind of unique, human-readable tokens (like "V0cM9tnV") ?
On Mon, Dec 29, 2008 at 6:44 PM, Thibaut Barrère

<thibaut.barr...@gmail.com> wrote:
> Hi,

> I'm pretty sure there is a number of options to achieve this, so I'm
> asking here. I often need to generate small unique tokens (like for
> invitation codes or unimportant authentication token).

> In the past I've been using Digest::SHA1.hexdigest(some string) which
> gives us something like "d2b7882fa08bb6de8dca62f16298683bfe4f0738".
> It's not very user friendly though, and definitely not small.

Hi Thibaut,

I have this rufus-mnemo that turns integers into "user friendly" strings.

http://github.com/jmettraux/rufus-mnemo

After a "sudo gem install rufus-mnemo"

you can do things like

---8<---
require 'rubygems'
require 'rufus/mnemo'

s = Rufus::Mnemo::from_integer(125704)

puts s
      # => 'karasu'
--->8---

Not exactly what you want, but could be funny. It's using a restricted
syllabary (the Japanese one) to turn integers into words (and back).

As twittered, it has the potential to generate insulting words. The
generated syllables sequences are quite easy to the latin ears though.

Best regards, meilleurs voeux pour 2009,

--
John Mettraux   -   http://jmettraux.wordpress.com


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dave Bass  
View profile  
 More options Dec 30 2008, 6:03 am
Newsgroups: comp.lang.ruby
From: Dave Bass <daveb...@musician.org>
Date: Tue, 30 Dec 2008 20:03:58 +0900
Local: Tues, Dec 30 2008 6:03 am
Subject: Re: Options to generate small, kind of unique, human-readable tokens (like "V0cM9tnV") ?
Generate a suitable random (or otherwise) integer and express in base
36:

  puts rand(36**6).to_s(36)

Dave
--
Posted via http://www.ruby-forum.com/.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Thibaut Barrère  
View profile  
 More options Jan 2, 3:09 am
Newsgroups: comp.lang.ruby
From: Thibaut Barrère <thibaut.barr...@gmail.com>
Date: Fri, 2 Jan 2009 17:09:54 +0900
Local: Fri, Jan 2 2009 3:09 am
Subject: Re: Options to generate small, kind of unique, human-readable tokens (like "V0cM9tnV") ?
Hey guys,

just want to say thank you all for the feedback and these options.
I'll gather these into a blog post later today, I think it's worth
sharing.

Thanks again!

Thibaut
--
http://blog.logeek.fr


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google