Let's say you have a table with 1000 records. You need the id field or something similar with unique values for each row.
In that case you could do this:
rand(0,1000);
Then with this number you check if the row with that id has the type=2, if that's the case, you can read x and y from it, otherwise go with it again...