Sunday, November 18, 2007

[firebird-support] Re: GUID/Random number generation?

--- In firebird-support@yahoogroups.com, Dean Harding
<dean.harding@...> wrote:
>
> randallsell wrote:
> > Hi,
> >
> > I have a requirement to create a unique 7 character string (numbers
> > and letters). In the file-based implementation, we simply extracted
> > the first 7 characters of a GUID. But I see no way to obtain a GUID in
> > PSQL. Surely there is a RANDOM function? But didn't find a reference
> > to such a beast in Helen's Bible.
> >
> > BTW- I can't used a Generator because these values are not internal.
> >
> > So, is there a free library I can obtain to either generate a GUID or
> > a random value?
>
> Well, certainly the first 7 characters of a GUID are not going to be
> unique, either!!
>
> When you say the value are not "internal" do you mean that some of the
> values are generated in the database, and so are generated outside the
> database?
>
> That would be fairly easy to solve with a generator, though: simply
> generate odd numbers inside the database, and even numbers outside the
> database. You can do that with the generator by using an "increment"
of 2.
>
> Dean.
>

You are correct - the first 7 are not necesarily unique. The full
algorythem in the file-based app does a loop, until it does generate a
unique entry, or stops after 5 seconds. To date, it has never failed
to come up with something before the 5 second timer expires.

The value created is given to the client - it becomes their password.
And it has to be 7 characters so I don't think that Generators are the
way to go. Their next value is too predictable. And I am trying to
keep the logic whole contained in the DB.

So ignoring GUIDs - as that was a hack anyway, it seems what I need is
a random function. Once I have that I can generate 7 random
alpha-numeric values. then run a query to ensure it is unique, and done.

all that is easy - once I know how to generate a random value.

cheers
-randall

__._,_.___
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Visit http://www.firebirdsql.org and click the Resources item
on the main (top) menu.  Try Knowledgebase and FAQ links !

Also search the knowledgebases at http://www.ibphoenix.com

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Recent Activity
Visit Your Group
Share Photos

Put your favorite

photos and

more online.

Need traffic?

Drive customers

With search ads

on Yahoo!

Endurance Zone

on Yahoo! Groups

Communities about

higher endurance.

.

__,_._,___

No comments: