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

Mark K. Kim vox-tech@lists.lugod.org
Thu, 31 Jan 2002 23:10:48 -0800 (PST)


What do you *want* it to do?

Including numbers will need some math trickery.  The place with 'z' and
'a' is where it's picking a letter between 'a' and 'z', but since numbers
aren't in a sequential order in the ASCII system, you can do something
like expanding the range and 'if'-ing the range for a letter or number.

-Mark

On Thu, 31 Jan 2002, Ryan wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> for some reason this is spitting out 3 char responses once in a while, anyone
> 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
> 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 = MIN_LEN + random() / (RAND_MAX / (MAX_LEN + 2 - MIN_LEN))-1;
>         if (string = malloc(length + 2), string == NULL)
>                 return NULL;
>         for (i = 0; i < length; i++)
>                 // does your head hurt yet?
>                 string[i] = 'a' + random() / (RAND_MAX / ('z' + 1 - 'a'));
>         // zero terminate!
>         i++;
>         string[i] = '\0';
>         return string;
> }
> - --
> No Microsoft products were used in any way for the creation of this message.
> 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=
> =kHSN
> -----END PGP SIGNATURE-----
> _______________________________________________
> vox-tech mailing list
> vox-tech@lists.lugod.org
> http://lists.lugod.org/mailman/listinfo/vox-tech
>

--
Mark K. Kim
http://www.cbreak.org/mark/
PGP key available upon request.