Original Code
Comments: function random_between:
Use ZZ instead of int. It'll treat the number as an integer class and allow you to call methods on it.
random finds a number in the range [0.0,1.0). Try ZZ.random_element(lower_bound,upper_bound) instead to get an integer in the range [lower_bound, upper_bound)
function SGP:
You have forgotten the parentheses! SGP() =)
Sage true and false are True and False (note the capitalization). Not essential, but a good habit.
Instead of repeat, the while struct has the following format:
while condition: #Do stuff #program continues after while loop
random_between should be ZZ.random, as in above point
no need for is. Remember to multiply! 2*p is a computation. 2p is not valid syntax.
x in Primes() is valid, but if you have an element of ZZ you can simply call the method num.is_prime() to get the same result