Regarding the pseudorandomization (#1): You need to come up with an algorithm that produces trial sequences adhering to your constraints. This can be difficult, and it may be impossible to do on-the-fly. See
https://www.millisecond.com/forums/Topic6419.aspx for some general thoughts on the topic. One possibility is to pre-generate several conforming sequences (either automatically, semi-automatically or manually), hard-code them into your script and simply have the script select one at random. Take a look at the AAT scripts in the library (
https://www.millisecond.com/download/library/AAT/ ), specifically at the trial sequence generation code starting at line 1366 in the mouse-version.
Setting an id is easy. You store the id in a <values> entry and log the value to the data file:
<values>
/ id = ""
</values>
...
<trial congruent>
/ ontrialend = [values.id = "c"; ]
...
</trial>
...
<data>
/ columns = [date time subject ... values.id ...]
...
</data>
Blocking certain stimuli for selection in a row can be achieved in multiple ways. If you use a common <list> for selection in the respective stimulus elements, you can use the /maxrunsize attribute to prevent the same item from being selected in a row.
<list malelist>
/ items = (1,1,2,2,3,3,...)
...
/ maxrunsize = 1
</list>
If you have multiple lists / stimulus pools, you can use the respective elements' /not attributes to exclude /block items from selection.
Question #4 can either be tackled just like #3 above. However, it seems to me there's also a relation to #1, the overall pseudorandomization issue. It might be best to treat this as an additional constraint and dealt with it during trial-sequence generation.
Hope this gives you a starting point.