Skip to content
EspañolWorkspace →

PSeInt Azar: random numbers

Gives a random whole number from 0 up to the given number minus one. It can change every run, like rolling a die.

Template
Azar
Open it in Codoritmo

Opens the editor with this example loaded. Run it step by step and watch the flowchart.

Worked example

A complete algorithm, ready to copy and run.

azar-random.psc · 4 lines
Algoritmo Example    dado <- Azar(6) + 1    Escribir dadoFinAlgoritmo

Output

dado is a number from 1 to 6.

This is what the console shows when the example runs.

2

Common mistake

Azar(6) gives 0 to 5; that's why you add 1 to simulate a die.

In a flowchart

This is how it appears in a flowchart, with the same shapes Codoritmo draws.

dado ← Azar(6) + 1
Used inside a calculation. It has no shape of its own; it's used inside a calculation. Flowchart: a process rectangle reading "dado ← Azar(6) + 1", with one arrow in and one arrow out.
Draw the flowchart of your own algorithm →

Template

The general form. Replace what's inside < > with your own data.

Azar · 1 line
Azar(<limite>)

Examples that use it

Programs from the example library where it appears, from the simplest to the most complete.

  • Hangman

    Guess a secret word letter by letter, with six mistakes allowed.

    Advanced
See every Randomness example →

More math functions

Codoritmo is an independent, open-source project inspired by PSeInt and compatible with its syntax. It is not affiliated with the PSeInt project. Official PSeInt website.