Lets say I have a region of mangrove forests (from a classified Landsat image) and I mask out all non mangrove pixels. I view this as a layer on the map and it shows the mangrove forests on the map hugging the coastline. Next, lets say I want to take a random sample of these mangrove pixels. As far as I can tell, this isn't possible, as when setting the parameters for a random sample, the 'whole image footprint' is considered, therefore giving most of the random samples as masked pixels. How can I set masked pixels as noData so when doing a random sample for a 'non-square' image that only the unmasked pixels are sampled. I've included a picture for clarity. Essentially I want the random samples to fall only within the mangrove forest, no for the 'whole image footprint'. I could do a stratified random sampling approach, whereby the sample points only fall within a class of my choosing, but I'm doing this for the whole of Indonesia, which returns a timeout.
As Nicholas pointed out, stratifiedSample will do this. It skips masked pixels. And if you get a timeout, generate the collection as an Export, where you get more time.