Random

<script src="./point_src/random"></script>

The random class provides a range of methods for producing random values.

The random object is instansiated for free:

const random = new Random()
// examples
random.int()
random.point()
Meta Data
title Random
dependencies ()
unused_keys ()
unknown_keys ()
filepath_exists True
path random
filepath random.js
clean_files ()

  • ClassDeclaration
    class comments:
    The minimum value the _point(value)_ can be, before the automatic 'float' method is used over the 'int' method.
    • property

      pointIntMin

      = 2
      from class_name
      dict_keys(['kind', 'word', 'computed', 'static', 'value', 'type', 'pos'])
    • method

      int

      (
      min = 1 , max
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])
      Generate an integer between 0 and the given min. Given 1 (default), the result will be either 0 or 1 random.int(10) 7 random.int(50) 30 random.int(300) 220
    • method

      float

      (
      min = 1 , max
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])
      Generate a decimal number between `0` and `1`. Provide a min/max to limit random.float() random.float(.2, 1)
    • method

      callOne

      (
      functions
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])
      Given many functions, call one.
    • method

      choice

      (
      selections
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])
      Give many items, return one
    • method

      index

      (
      selections
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])
      Given many, return an index
    • method

      string

      (
      multiplier = 1 , rot = 32
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])
      Return a random string
    • method

      radix

      (
      v , rot = 32
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])
    • method

      point

      (
      multiplier = 1 , method = undefined
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])
      return a random point(), with the X/Y values set as random*multplier
    • method

      shuffle

      (
      points , max = 1
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])
    • method

      within

      (
      point , max = 0.5
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])
      Return a random 2D position within the given point. within({ x: 100, y: 100, radius: 100}) {x: 79, y: 50}
    • method

      xy

      (
      multiplier = 1
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])
      return two random values between 0 and 1 multiplied by the given value `multiplier`. This is similar to the random.point() function, except it only returns an object of {x,y}
    • method

      gaussianFloat

      (
      mean , stdev = 1
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])
      Standard Normal variate using Box-Muller transform.
    • method

      gaussian

      (
      start , end , mean , stdev = 1
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])
    • method

      polar2D

      (
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])
    • method

      color

      (
      h = 360 , s = 100 , l = 100
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])
      Return a random `hsl` color string, random.color() random.color(360, 100, 100) random.color(360, [30, 100], [60,100])
    dict_keys(['kind', 'word', 'parentName', 'type', 'body', 'comments', 'pos'])
  • VariableDeclaration
    const

    random

    =
    new Random ( )
  • ExpressionStatement

    :

    dict_keys(['type', 'expression', 'pos'])
  • VariableDeclaration
    const

    randomizePoint

    =
    function ( px , y )
    Perform random() on the X and Y. If a point is given, randomize to the _max_ of the given point If a single number is given, assume _square_ If no params are given, discover the stage size. Use `Point.random()` for the same form, as a new point let p = new Point() p.randomize(100, 400) p.randomize(100) // 100, 100 p.randomize(new Point(100, 400)) // 100, 400 if one of the keys is undefined, no change occurs: p.setXY(500,700) p.randomize(100, undefined) // 100, 700 p.randomize(undefined, 400) // 500, 400 p.randomize(undefined, undefined) // 500, 700 // no change occurs. Note; no params will randomize as much as possible (the stage size) p.randomize() // 800, 600 Other features would be nice: + random in rect (like stage): p.randomize(rect|dimensions) + Randomize other values, e.g radius, colors p.randomize(['x', 'y', 'radius', 'mass']) // randomize x to max 400, radius to max 50 p.randomize({ x: 400, radius: 50}) + In the future, the _origin_; randomize relative to a point: p.randomize({point, relative: true})