import math
import random


def random_word_fix(tokens, vocab_range, mask, default_num=10):
    """
    Masking some random tokens for Language Model task with probabilities as in
        the original BERT paper.
    :param tokens: list of int, tokenized sentence.
    :param vocab_range: for choosing a random word
    :return: (list of int, list of int), masked tokens and related labels for
        LM prediction
    """
    total_len = len(tokens)
    mask_len = math.ceil(default_num * 0.15)
    mask_num = random.sample([_ for _ in range(total_len)], mask_len)
    output_label = [-1 for _ in range(total_len)]
    for mask_index in mask_num:
        token = tokens[mask_index]
        tokens[mask_index] = mask
        output_label[mask_index] = token
    return tokens, output_label