> For the complete documentation index, see [llms.txt](https://random-docs.radix.live/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://random-docs.radix.live/readme.md).

# .Random

### Introduction

.Random is a solution designed to provide a secure and reliable source of randomness for the Radix ledger. Whether you're developing raffles, minting NFTs, gaming applications, or any other components on Radix, our randomness service ensures fairness and unpredictability.

### The Problem

There is no way to produce any random outcome on the Radix ledger. The current time cannot be used as a source of randomness because available time precision (up to a second) is insufficient. The transaction hash is random enough, but the client generates it, so the User can "mine" any desired TX hash. Bringing something random from outside the ledger and passing it to your Component is possible; however, having a Transaction Manifest and previewing transactions in the Wallet means that a user can reject submitting the transaction if the projected outcome is not good enough for them.

### The Solution

The only way to solve this is to bring something random from outside the ledger onto the ledger in a separate transaction. This way, we can guarantee that the User doesn't know the result until they have committed the transaction, and there is no going back.

### How it Works

To make it work, we have developed a framework that consists of three parts:

1. `RandomComponent` - an on-ledger component that allows you to request randomness.
2. `Watcher` - an off-ledger service that monitors all invocations of `RandomComponent` and brings the random bytes to the ledger.
3. `Random` - a small 1Kb library that you can include in your component to conveniently convert random bytes into any number of pseudo-random outcomes.&#x20;

<figure><img src="/files/DqBLpbkAnn1ZuOtVl2gA" alt=""><figcaption></figcaption></figure>

### Examples

You can find examples on [GitHub](https://github.com/dot-random/examples).

### Authentication

Ideally, you would like to allow only RandomComponent to call the callback method on YourComponent, preventing anyone else from misusing it. You can choose of the two ways to ensure this:

1. Grant access for each particular callback transaction to `RandomComponent` (recommended). You pass a bucket with some token to `request_random()`. Then you can verify that the same bucket is returned back to you in the callback. \
   See an example in [bucket\_transfer\_auth.rs](https://github.com/dot-random/examples/blob/master/bucket_transfer_auth/src/bucket_transfer_auth.rs).
2. Allow `RandomComponent` to call the method on YourComponent freely. You protect the callback method with `method_auth` , requiring our special badge (find the resource ID [here](https://github.com/dot-random/dot-random?tab=readme-ov-file#ids-on-mainnet)).\
   See an example in [badge\_auth.rs](https://github.com/dot-random/examples/blob/master/badge_auth/src/badge_auth.rs).

### Testing

You can test with TestRunner (see examples above) or TestEnv. RESim is not supported at the moment.

### Service Fee

Every time `request_random()` is invoked, we charge a $0.06 royalty fee (1 XRD based on current network settings)

### Transaction Fees

When your callback method is executed in the second transaction, someone has to pay the transaction fees. There are two options:

1. You pay for the transaction, by executing [`lock_fee`](https://docs.radixdlt.com/docs/en/buckets-and-vaults#fungiblevault-methods) inside your callback method, even if the transaction fails (remember that the methods should be [authenticated](#authentication)).&#x20;
2. You do nothing and the transaction cost will be put on users. `request_random()` invocations will require additional royalties to pay for the future transaction, based on the average total transaction costs incurred when executing your callback.

{% embed url="<https://github.com/dot-random/dot-random>" %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://random-docs.radix.live/readme.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
