GSDP:GAM100/CProcessing/randomRangeInt()

From Inside
Jump to: navigation, search

randomRangeInt()

Description

Gives a random unsigned int from the range specified in the input parameters. Both inputs must be non-negative and if min is greater than max it always returns min.

Parameters

randomRangeInt(unsigned int min, unsigned int max)

  • min - (unsigned int) The minimum value of the random range.
  • max - (unsigned int) The maximum value of the random range.

Example

static int val1;
static int val2;
static int val3;

void init()
{
    // Set initial values
    val1 = randomRangeInt(0, 255);
    val2 = randomRangeInt(0, 255);
    val3 = randomRangeInt(0, 255);

    // Set draw mode to center
    rectMode(CENTER);
}

void update() 
{
    // Draw a white background
    background(color(255, 255, 255, 255));

    // Every ten frames change the color
    if(frameCount % 10 == 0)
    {
        val1 = randomRangeInt(0, 255);
        val2 = randomRangeInt(0, 255);
        val3 = randomRangeInt(0, 255);
    }

    // Set the draw color
    fill(color(val1, val2, val3, 255));

    // Draw a square in the center of the screen
    rect((float)canvasWidth/2, (float)canvasHeight/2, 50.0f, 50.0f);
}

Related

Personal tools
Namespaces

Variants
Actions
Navigation
NameSpaces:>
Tools
Dynamic:>