Without knowing more details I can't think of any helpful advice.
> b is supposed to be a random integer between 1 and p, right?
b should be between 1 and p-1.
> I know
> that randint(x,y) includes x and y, should I use another function?
No, that should be fine.
William