def is_grandcanonical(trajectory, tests=1):
    """
    Simple test to check if a trajectory is grandcanonical.
    i.e. if the number of particles fluctuates.

    We compare the first frame to an integer number `tests` of other
    frames starting from the end of `trajectory`.
    """
    is_variable = False
    if tests > 0:
        skip = max(1, int(len(trajectory) / float(tests)))
    else:
        skip = 1
    N0 = len(trajectory[0].particle)
    for sample in range(len(trajectory) - 1, 0, -skip):
        N1 = len(trajectory[sample].particle)
        is_variable = False
        if N0 != N1:
            is_variable = True
            break
    return is_variable
