For 2nd, i recommend using the php function uniqid()
, takes some of the work of user.
For 3rd i think the best way to implement is to keep adding the id’s after each shortcode call to a global/static variable in an array & then hook a function to wp_footer
that reads from this variable to get all the id’s & generate the neccessary javascript
For 1st, add this inside the shortcode function-
STATIC $flag = false;
if(!$flag) {
$flag = true;
// include all your scripts that you want to include in the page only once
// These statements will be executed once per page load
// irrespective of how many times shortcode is called.
}