@triton.autotune(configs=[triton.Config({'BLOCK_SIZE_M': 8, 'BLOCK_SIZE_N':
    4, 'BLOCK_SIZE_K': 32})], key=['M', 'N', 'K'])
@triton.jit
def random_matrix_kernel(r_ptr, seed, M, K, N, stride_dm, stride_dk,
    stride_dn, BLOCK_SIZE_M: tl.constexpr, BLOCK_SIZE_N: tl.constexpr,
    BLOCK_SIZE_K: tl.constexpr):
    pid = tl.program_id(axis=0)
    num_pid_m = tl.cdiv(M, BLOCK_SIZE_M)
    num_pid_n = tl.cdiv(N, BLOCK_SIZE_N)
    pid_m = pid // num_pid_n
    pid_n = pid % num_pid_n
    offset_m = pid_m * BLOCK_SIZE_M
    offset_n = pid_n * BLOCK_SIZE_N
    offset_k = 0
    d_offsets = block_offsets_3d(M, K, N, stride_dm, stride_dk, stride_dn,
        offset_m, offset_k, offset_n, BLOCK_SIZE_M, BLOCK_SIZE_K, BLOCK_SIZE_N)
    offs_k = tl.arange(0, BLOCK_SIZE_K)
    for k in range(0, tl.cdiv(K, BLOCK_SIZE_K)):
        k_mask = offs_k[None, :, None] < K - k * BLOCK_SIZE_K
        random_masks = tl.random.rand(seed, d_offsets) > 0.5
        tl.store(r_ptr + d_offsets, random_masks.to(tl.int8), mask=k_mask)
        d_offsets += BLOCK_SIZE_K * stride_dk
