hi there,

I am writing a simple char device that generates pseudo-random numbers, the problem is when I try to read from that char device, i.e when I write this command "cat (device's dictionary)" it reads 3 times which is really weird. anyone can help me out please.

here is some of my code

unsigned int random_seed;
char msg[256];
int msg_len;

unsigned char rg_hw()
	random_seed = random_seed * 1103515245 + 12345;
	return (unsigned char)((unsigned int)(random_seed / 65536) % 256);

ssize_t read(struct file *file, char __user *buf, size_t len, loff_t *offset)
	printk(KERN_ALERT "reading a char device, seed = %d\n", random_seed);

	sprintf (msg, "%d", rg_hw());
	msg_len = strlen(msg);	

	if (*offset >= msg_len)
	      	return 0;  

  	if (*offset + len >= msg_len)
      		len = msg_len - *offset;  

	if(copy_to_user(buf, msg + *offset , len))
		printk(KERN_EMERG "loool\n");
		return -EFAULT;

	*offset += len;
	return len;
here is the printk messages i wrote to test my read device
Starting char device
allocated a new major, 248
opend the char device, with minor 0
reading a char device, seed = 0
reading a char device, seed = 12345
reading a char device, seed = -740551042
releasing the char device.
thanks in advance

EDIT: upon further testing, i think i found out what is the problem, i made a tester from user space and used the functions open and read, now the problem is that reads only one random number then stops, is there a way to make it read as many times as the buffer's size?