import random


def slice_dir_to_int(slice_dir):
    """
    Convert slice direction identifier to int.

    Args:
        slice_dir: x|y|z|xyz  (string)

    Returns:
        0|1|2 (int)
    """
    if slice_dir == "xyz":
        slice_direction_int = int(round(random.uniform(0, 2)))
    elif slice_dir == "x":
        slice_direction_int = 0
    elif slice_dir == "y":
        slice_direction_int = 1
    elif slice_dir == "z":
        slice_direction_int = 2
    else:
        raise ValueError("Invalid value for 'training_slice_direction'.")
    return slice_direction_int