Your code has 3 problems:-
1. The 12F629 has a comparator which is connected to GP0, GP1 and GP2 by default. To use these pins for digital I/O you should disable the comparator by setting CMCON to 7 (comparator off). Without this change GP0 will always read 0 and your program never generates a random number.
2. You are outputting the random number on GP0-2, but also trying to detect a high level (switch?) on GP0. You should move that input to an unused pin. GP3 is the obvious choice because it can only be an input (also make sure that 'GP3/MCLR pin select' is disabled in 'Edit Project', to enable the GP3 input).
3. You are generating a random number between 1 and 6, but the array hex_value[] requires an index between 0 and 5. Your code reads one byte past the array (which happens to contain the value 6) so it only returns values from 2 to 6.
Here is the corrected code:-
unsigned char rundom(int Limit, int M) {
unsigned char result;
static unsigned int M;
M= (M*32719+3)%32749;
result=((M%Limit)); // random number between 0 and limit-1
return result;
}
void main() {
unsigned char k,pattern,seed=1;
unsigned char hex_value[]={0x01,0x02,0x03,0x04,0x05,0x06};
TRISIO = 0; // all pins are output except GP3 (which is always an input)
CMCON = 7; // disable comparator
GPIO.B4 = 1;
while(1){
if(GPIO.B3==1){
k=rundom (6,seed) ;
pattern=hex_value[k];
GPIO=pattern;
delay_ms(7000);
GPIO=0;
}
}
}