Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Bases de datos > Firebird e Interbase
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 13-04-2008
Avatar de xEsk
[xEsk] xEsk is offline
Miembro Premium
 
Registrado: feb 2006
Posts: 454
Poder: 21
xEsk Va por buen camino
Una solución que se me ocurrió fue reemplazar la función rand() del Firebird por otra creada por mi (importarla en forma de UDF), pero después pensé, que es muy raro que lleve un random y no un randomize, así que mire manualmente en el fichero ib_udf2.sql que lleva el Firebird, y efectivamente, he encontrado el srand().

Te copio su descripción:
Código SQL [-]
/*****************************************
 *
 *  s r a n d
 *
 *****************************************
 *
 * Functional description:
 *  Seeds the random number generator using
 *  the current time and returns the first
 *  pseudo-random number (between 0 and 1)
 *  in the new sequence.
 *
 * Note:
 *  Two srand() calls performed within a second
 *  will return the same value.
 * 
 *****************************************/
DECLARE EXTERNAL FUNCTION srand 
  RETURNS DOUBLE PRECISION BY VALUE
  ENTRY_POINT 'IB_UDF_srand' MODULE_NAME 'ib_udf';

Saludos.
Responder Con Cita
  #2  
Antiguo 15-04-2008
Avatar de DarkDudae
DarkDudae DarkDudae is offline
Miembro
 
Registrado: abr 2006
Posts: 177
Poder: 21
DarkDudae Va por buen camino
Ante todo, muchas gracias. Funciona perfectamente.

Cuando buscaba una solución, también indagué en la documentación del firebird, pero cuando leí que el srand() era la antigua función rand() que ha sido sustituida recientemente por la rand() actual para evitar que la semilla arrojase valores aleatorios iguales cuando se ejecutaban diversas llamadas en el mismo segundo, la dejé en el olvido:

Cita:
UDFs Added and Changed
IB_UDF_rand() vs IB_UDF_srand()
IB_UDF_lower
UDFs added or enhanced in Firebird 2.0's supplied libraries are:
IB_UDF_rand() vs IB_UDF_srand()
F. Schlottmann-Goedde
In previous versions, the external function rand() sets the random number generator's starting point based on the current time and then generates the pseudo-random value.
srand((unsigned) time(NULL));
return ((float) rand() / (float) RAND_MAX);

The problem with this algorithm is that it will return the same value for two calls done within a second.
To work around this issue, rand() was changed in Firebird 2.0 so that the starting point is not set explicitly. This ensures that different values will always be returned.
In order to keep the legacy behaviour available in case somebody needs it, srand() has been introduced. It does exactly the same as the old rand() did.
No obstante, para mis necesidades, las limitaciones del antiguo rand() no son tales. En fin, cada función tiene sus pros y sus contras.

Un saludo!
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Numero aleatorio de productos principiante22 Impresión 6 04-03-2008 01:24:08
Alguien sabe como usar la Función Rand() en firebird DANNY777 Firebird e Interbase 2 26-01-2008 16:19:17
Select aleatorio JBalda Firebird e Interbase 11 27-06-2007 20:28:23
Orden aleatorio al 7o digito!!! jdattoli Tablas planas 1 20-10-2005 18:15:09
Presentar ordern aleatorio en un Select aerosB4 Firebird e Interbase 4 16-08-2004 12:53:21


La franja horaria es GMT +2. Ahora son las 21:47:25.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi