import random


def createRandomString(length, numOnes):
    """Returns a random binary string with specified number of randomly located
    ones."""
    counter = numOnes
    string = ''
    for i in range(length):
        string += '0'
    while counter !=0:
        loc = random.randrange(length)
        while string[loc] == '1':
            loc = random.randrange(length)
        string = string[:loc] + '1' + string[loc+1:]
        counter -= 1
    return string