Subject: Random number in 4gl
From: [email-masked] (Marco Greco)
Date: 19 Nov 1996 06:28:24 -0500
Newsgroups: comp.databases.informix

> Does anyone know of a random number generator in 4gl (Informix? (Not using c 
> func call)

	4gl doesn't have a built in random number generator, as you have 
guessed, so your only chance is to write one in c, and call that from within 
4gl. Enclosed find my own.

---------------- cut here crndc.c -----------------
#include <stdio.h>

unsigned int seed=1;

/*
**  gets next random number
*/
get_rand(nargs)
int nargs;
{
    long i,j;
    popint(&i);
    seed=(0x8088405*seed+1) & 0xFFFF;
    j=seed % i;
    retint(j);
    return(1);
}

/*
**  sets the random generator seed
*/
start_rand(nargs)
int nargs;
{
    int i;
    popint(&i);
    seed=i;
    return(0);
}

/*
**  returns the current seed
*/
say_seed(nargs)
int nargs;
{
    retint(seed);
    return(1);
}

/*
**  asks the system clock for a seed
*/
get_seed(nargs)
int nargs;
{
    int i;
    i=(time(NULL)) & 0xFFFF;
    retint(i);
    return(1);
}

-------------------- end cut ---------------------------

HTH,
Marco
____________________________________________________________________________ 
rem radioterapia, which I immeritately manage, seldom agrees with what I say

marco greco   (Catania, Italy)      Work:
[email-masked]                  rem radioterapia 39 95 447828 fax 446558
(was [email-masked])        Achea            39 95 503117