[vox-tech] [C newbie]C program is acting weird...

Ryan vox-tech@lists.lugod.org
Thu, 31 Jan 2002 22:54:16 -0800


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

for some reason this is spitting out 3 char responses once in a while, an=
yone=20
have any ideas? I don't know much C, this is just some code I modified.

Also, if anyone knows how to get it to include numbers mixed in with the=20
letters i'd like to know how.
- ------

#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <signal.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>

#include "version.h"

#define SESSION_TIMEOUT 20

#define MAX_RESPONSE 200
#define MAX_REQUEST 100

#define MIN_LEN 4
#define MAX_LEN 9

char *randusername()
{
        char *string;
        int i, length;
        // randomly choose a length betweem MIN_LEN and MAX_LEN
        length =3D MIN_LEN + random() / (RAND_MAX / (MAX_LEN + 2 - MIN_LE=
N))-1;
        if (string =3D malloc(length + 2), string =3D=3D NULL)
                return NULL;
        for (i =3D 0; i < length; i++)
                // does your head hurt yet?
                string[i] =3D 'a' + random() / (RAND_MAX / ('z' + 1 - 'a'=
));
        // zero terminate!
        i++;
        string[i] =3D '\0';
        return string;
}
- --
No Microsoft products were used in any way for the creation of this messa=
ge.
PGP Public key at http://mother.com/~ryan/ryan_at_mother_dot_com.asc
It is also on the servers: Key ID 0x72177BC7
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE8WjuYEd9E83IXe8cRArkBAJ9KZAmEZrqQbbBWY0MBv6EFid9ZRACfXKDc
G2u947jK74bVhkLKjjEPsIg=3D
=3DkHSN
-----END PGP SIGNATURE-----