Subject | Re: [firebird-support] 'random' generator value output? |
---|---|
Author | unordained |
Post date | 2004-07-13T20:59:35Z |
Generators are sequential to prevent conflicts. (In fact, they're non-transactional to make sure.)
You probably won't want fully random numbers, as you'd get conflicts. And random numbers require a
range, generally. You've already provided one -- 5 digit numbers. So we have a finite set of
sequential numbers, and a finite set of shuffled numbers: we can map between them.
You can pre-create a table of sequential numbers to 'random' numbers (two integer fields.) Reset
the generator to the lowest sequential number. When you need another random one, pull a generator
value, look up the equivalent random number, and use that. So long as both columns are unique in
the lookup table, you'll be fine.
How you generate the table is up to you ... I would probably just create a quick php or C program
that generates a unique list of numbers, shuffles them, then inserts them with sequential id's
attached.
It's an idea, at least. (5 digits, so 100k rows. Slightly expensive to pre-create, but ... oh well?)
-Philip
---------- Original Message -----------
From: "rbd523" <robbyd@...>
To: firebird-support@yahoogroups.com
Sent: Tue, 13 Jul 2004 17:36:25 -0000
Subject: [firebird-support] 'random' generator value output?
You probably won't want fully random numbers, as you'd get conflicts. And random numbers require a
range, generally. You've already provided one -- 5 digit numbers. So we have a finite set of
sequential numbers, and a finite set of shuffled numbers: we can map between them.
You can pre-create a table of sequential numbers to 'random' numbers (two integer fields.) Reset
the generator to the lowest sequential number. When you need another random one, pull a generator
value, look up the equivalent random number, and use that. So long as both columns are unique in
the lookup table, you'll be fine.
How you generate the table is up to you ... I would probably just create a quick php or C program
that generates a unique list of numbers, shuffles them, then inserts them with sequential id's
attached.
It's an idea, at least. (5 digits, so 100k rows. Slightly expensive to pre-create, but ... oh well?)
-Philip
---------- Original Message -----------
From: "rbd523" <robbyd@...>
To: firebird-support@yahoogroups.com
Sent: Tue, 13 Jul 2004 17:36:25 -0000
Subject: [firebird-support] 'random' generator value output?
> I have a generator attached to a primary key field on a certain------- End of Original Message -------
> table via a BEFORE INSERT trigger. I can get sequential values from
> this generator fine, but I was wondering if there was any way (using
> generators or not) to get 'random' values from the generator that,
> while 'random', won't conflict with any of the primary key ID values
> already in the table. ....basically it amounts to generating a
> random, unrepeated sequence for my primary key (or any other unique
> field for that matter).
>
> This would be useful to me because users of the system will be
> assigned a table that cooresponds to that unique ID, and there is a
> bit more security in giving them a random 5 digit ID
> (like '35464', '97483' for the next ID, etc) instead of a sequential
> ones like '10001', '10002'... I would like the level of security
> that nonsequential IDs bring, but we don't need enough security to
> warrant the entering of a seperate PIN.
>
> Is anything like this possible? If not, I might have to go that ID,
> PIN route instead.
>
> Thanks,
>
> Robby
>
> ------------------------ Yahoo! Groups Sponsor --------------------~-->
> Yahoo! Domains - Claim yours for only $14.70
> http://us.click.yahoo.com/Z1wmxD/DREIAA/yQLSAA/67folB/TM
> --------------------------------------------------------------------~->
>
> Yahoo! Groups Links
>
>
>