y Statement (or Seed Statement)
Prev | Score Statements and GEN Routines | Next

## y Statement (or Seed Statement)

a — Set seed for random numbers.

## Description

Set seed for random numbers, either from p1 or, if omitted, the clock.

## Syntax

    y [p1]

## Initialization

p1 -- An integer value between 0 and 232 used as a new seed for random numbers. If omitted, the system clock value will be used instead.

## Performance

The tilde symbol ˜ can be used in an expression wherever a number is permissible to use. Each ˜ will evaluate to a random value between zero (0) and one (1). If there is no y statement in the score, the pseudo-random generator will yield the same numbers in each performance. If a fixed seed is given, a different predictable series of pseudo-random numbers will be generated from this seed. If a y statement is used without p1, the system clock will be used as a seed, yielding a different series of pseudo-random numbers for each performance.

## Examples

Here is an example of the y statement. It uses the file y_statement.csd.

Example 1271. Example of the y statement.

    <CsoundSynthesizer>
    <CsOptions>
    ; Select audio/midi flags here according to platform
    ; Audio out   Audio in    No messages
    -odac           -iadc     -d     ;;;RT audio I/O
    ; For Non-realtime ouput leave only the line below:
    ; -o 0dbfs.wav -W ;;; for file output any platform
    </CsOptions>
    <CsInstruments>

    ; Initialize the global variables.
    sr = 44100
    ksmps = 10
    nchnls = 2
    0dbfs = 1

    instr 1
      print p4
    endin
    </CsInstruments>
    <CsScore>

    y

    i 1 0 1 [~ * 9 + 1]
    i 1 + 1 [~ * 9 + 1]
    i 1 + 1 [~ * 9 + 1]
    i 1 + 1 [~ * 9 + 1]
    e

    </CsScore>
    </CsoundSynthesizer>

Each time this example is run, different values between 1 and 10 will be displayed. The seed used will be displayed as well.

## Credits

Author: John ffitch, 2014

New in version 6.03

Prev | Up | Next
x Statement | Home | { Statement