(* Copyright 2012-2015 by Adam Petcher.				* * Use of this source code is governed by the license described	* * in the LICENSE file at the root of the source tree.		*)
(* RndNat -- a computation that returns a random nat uniformly distributed in a specified range. *)
Set Implicit Arguments.
Definition RndNat_unchecked(n : nat) :=
v <-$ {0,1} ^ (lognat n);
let n := (bvToNat v) in
ret n.
Definition ltNatBool := fun x1 x2 => if (lt_dec x1 x2) then true else false.
(* RndNat uses Repeat to get a number strictly less than n *)
Definition RndNat(n : nat) :=
(Repeat (RndNat_unchecked n) (fun x => (ltNatBool x n))).
Notation "[ 0 '..' n )" := (RndNat n)
(right associativity, at level 77) : comp_scope.

(* Specifications: *)
Lemma well_formed_RndNat : forall n,
n > O ->
well_formed_comp (RndNat n).