# How to write algorithm that works with random variables

I'd like to write an algorithm with algorithmicx that does some operations only if random variables extracted from a uniform distribution are in a specific range.

How can i do that in a mathematical style?

I don't want something like

\State $a \gets uniform(0,1)$


but maybe a better version of

\State $a \gets A \sim \mathcal{U}(0,1)$


(i don't even know if it's correct, but i hope you understand what i'm looking for).

The code after the extraction could look like the following

\If {$a \geq 0.5$}
% do something
\Endif

• Welcome! Please edit your question to provide a complete minimal example we can compile. Mere fragments of code (pseudo-code?) aren't really helpful. To be honest, I'm utterly confused by your question. Aren't these packages for typesetting algorithms? But you seem to want to implement one, rather than typesetting it. That is, you seem to expect \If ... \Endif to do something conditionally, which isn't what it is for. – cfr Sep 1 '17 at 2:36