PDA

Visualizza la versione completa : [c] Random character


pistilloi
22-01-2013, 22:30
//rand.c

#include<stdlib.h>
#include<stdio.h>
#include<time.h>

int main()
{
srand(time(NULL));

unsigned char c;

c = 'a' + rand() % 'z' ;

printf("random character: %d %c\n", c, c);

return 0;
}


$ cc rand.c -o rand
$ ./rand
random character: 187 �
$ ./rand
random character: 114 r
./rand
random character: 114 r
./rand
random character: 169 �
$

Why?

pistilloi
22-01-2013, 22:38
Che imbecille...


//rand.c

#include<stdlib.h>
#include<stdio.h>
#include<time.h>

int main()
{
srand(time(NULL));

unsigned char c;

c = 'a' + rand() % ('z'-'a') ;

printf("random character: %d %c\n", c, c);

return 0;
}

Loading