import random


def random_anagrammable(Nsamples, wbags, Nanagrams=1, Lmax=None):
    """
    Randomly sample words from a dictionary which also have an anagram in the dictionary.

    Parameters
    ----------
    Nsamples : int
        Number of words to sample
    wbags : mapping
        Structure mapping `wordbag(word)` to a set of all anagrams of that word.
    Nanagrams : int, optional
        Number of anagrams a word must have to be suitable. Defaults to 1.
    Lmax : int, optional
        Maximum length of word to sample.
    """
    candidates = [w for ws in wbags.values() 
                    for w in ws 
                    if (Lmax is None or len(w) <= Lmax) and len(ws) > 1]
    return random.sample(candidates, Nsamples)