# Randomly 1 or -1

```lua
math.random(1,2) * 2 - 3
```

The above code can be used to get a random value of either 1 or -1.

1 \* 2 = 2 - 3 = -1

2 \* 2 = 4 - 3 = 1

Getting 1 or -1 can be useful for setting a value to be randomly negative or positive when multiplied by the random value. This can be useful for example for setting a direction randomly.

{% embed url="<https://repl.it/@pkeod/Randomly1or-1>" %}


---

# Agent Instructions: 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://read.bookofdefold.com/defold-a-z/lua-tips/randomly-1-or-1.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.
