# What is the compleixty of this algorithm?

The algorithm is as follows:

a = rand  % a random number between 0 and 1
b = a
while b == a
b = rand
end


Here rand is a function that returns a random number, generated uniformly, between 0 and 1. Let us say that this is the MATLAB function rand.

What is the time complexity of this algorithm?

It looks like the best and average complexities are $O(1)$ and the worst complexity is unbounded.

• Complexity in what model of computation? What form might the numbers $a$ and $b$ take? What exactly does rand do? In most actual programming languages, it gives a pseudorandom number so there are actually deterministic bounds on exactly how long it will take to get back to the initial value. – David Richerby Jun 23 '16 at 15:05
• The title you have chosen is not well suited to representing your question. Please take some time to improve it; we have collected some advice here. Thank you! – D.W. Jun 23 '16 at 17:47
• – Raphael Jun 24 '16 at 10:39