Finding collisions of the first few bits of a SHA-1 hash
I realized that while typing this, you should look into the Birthday Attack, which will probably much more elaborated than my answer, lol.

Considering your have 36 bits of data, it means you have a total number of possibilities of \$2^{36} = 68719476736\$. Based on the Pigeonhole principle, if you compared the hashed of 68719476736 different strings, you'd get a collision.

So that's easy! All you need to do is run this (pseudocode): 

hashset = (new hashset that uses your hashing algorithm)
for(i = 0; i &lt; 68719476736 + 1; i++) {

    if hashset.contains(string(i)) break; 

    hashset.add(string(i));
}

print("This took " + i + " tried!")


With this, you're guaranteed to get a collision. But there's a problem. If every iteration took 100 milliseconds, you'd need about 217 years to get a solution. Tell your teacher your great-great-grandchildren will get back to you with a solution. You could also buy 2000 computers to run this in ~40 days.

My algorithm is pretty much guaranteed to finish (assuming none of the computers crash in any way), yours isn't. This is more of a lesson on "how to test things", which is valuable for developers. When you want to test something, try not to be random. The thing with your algorithm is that maybe you wouldn't ever get collisions. I understand that you kind of need randomness if you want this to finish running this one day.

So the question is, what could we do to make this better?

We could check about how many different strings we'd need to get a good enough chance there's a collision. It's kind of the Birthday Problem which gives us an easy way to calculate what are the chances n different persons have the same birthday in a group of m persons.

We can use the formula under Approximation of number of people and adapt it to our problem to understand that if we had 68719476736 + 1 strings in our possession (for example, every number between 1 and 68719476736 + 1), you'd need to pick 308652 of those to have about 50% chances of having a collision.

What you could try is randomly take 308652 numbers between 1 and 68719476736 + 1 and hash them to find a collision. Repeat this as long as you don't have a collision. 

The pseudocode would look like this :

generator = RandomBigIntGenerator()
numbers = []

for(i = 0; i &lt; 308652; i++) {
    numbers.add(generator.random(1,68719476736+1))
}

hashset = {} (With your hashing function)
for n in numbers {
    if hashset.contains(n) {
        print("yay done");
        break;
    }
    hashset.add(m);
}


All in all, you can hope to have collisions, but you need computing power.

In a code review point of view :


You need to keep track of the strings you already tried, they give you valuable information that can actually help you find collision.
Don't be too random when you create your strings.
Understand that 68719476736 is a biiggg number, but still so much smaller than the 1461501637330902918203684832716283019655932542976 possible values the SHA1 have :)