> For the complete documentation index, see [llms.txt](https://lita.gitbook.io/lita-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lita.gitbook.io/lita-documentation/quick-start/valida-compiler-toolchain/rust-usage.md).

# Rust Usage

## Usage Instructions for Rust

For examples of how to build a Rust program which compiles and runs on Valida, see the `/valida-toolchain/examples` directory in a docker image or the `examples` directory in the release tarball. You can use any of these examples as a starting point for developing your own programs using the Valida toolchain.

You can start from an empty project as well:

1. `cargo new valida-project`.
2. `cd` into the project:

```bash
cd valida-project
```

3. Enter the Valida shell or the Docker toolchain shell, following the instructions specific to your selected [installation method](/lita-documentation/quick-start/installation-and-system-requirements.md).<br>
4. Build the project:

```
cargo +valida build --release
```

5. Run the code:

```
valida run --fast target/valida-unknown-baremetal-gnu/release/valida-project log
```

## Randomness in Rust programs

If your program uses randomness then most probably it depends on the `getrandom` crate. You can check if it does by inspecting the output of the `cargo tree` command. In that's the case a patched version of that crate must be used. Update your `Cargo.toml` by adding `patch` section:

```
[patch.crates-io]
getrandom = { git = "https://github.com/lita-xyz/getrandom.git", branch = "v0.2.16-valida" }
```

or

```
[patch.crates-io]
getrandom = { git = "https://github.com/lita-xyz/getrandom.git", branch = "v0.3.3-valida" }
```

depending on whether your program depends on `getrandom` 0.2.\* or 0.3.\*

After modifying Cargo.toml make sure that the Valida version of `getrandom` is used by running:

```
cargo update getrandom
```

Note that currently the random number generator uses a static seed and thus behaves deterministically, producing the same result on each run of a program.

## Input and output

Valida programs can interact with the environment using the input and output tapes. In the Valida zk-VM, the input tape is mapped to `stdin`, or the input file specified on the command line. The output tape is mapped to `stdout`, and the output file specified on the command line for `valida run`.&#x20;
