import random


def gen_random_walk(start=100, n_steps=50, num_range=(-100, 100),
                    new_step_chance=0.5):
    """
    inputs:
        start - start value for walk
        n_steps - number of steps to take from starting point
        num_range - range of values to sample for steps
        new_step_chance - probability of taking step different
                          from last step (ie if 0 then all steps will be
                          same value)
    output: list of values in walk
    """
    # init start point for walk
    walk = [start]
    # gen a default step
    step_val = random.randrange(num_range[0], num_range[1])
    for i in range(n_steps):
        # chance to take a new step or take last step again
        if random.random() > (1 - new_step_chance):
            # update step value
            step_val = random.randrange(num_range[0], num_range[1])
        # add step to last position
        new_pos = walk[i - 1] + step_val
        # append new position to walk history
        walk.append(new_pos)

    return walk