RandUtils

An asset by julienvanelian
The page banner background of a mountain and forest
RandUtils hero image

Quick Information

0 ratings
RandUtils icon image
julienvanelian
RandUtils

A collection of RNG (Random Number Generator) utilities for the Godot Engine.This addon provides:- Random string generation- Random boolean with ability to specify probability- Random normalized Vec2 and Vec3- Random Color with customizable HSV ranges- Random item(s) from array- Random byte(s)This addon provides a RandUtils class, which contains static methods used to generate data. As the methods are static, you don't have to instantiate the class.Check the readme for more information, including usage: https://github.com/JulienVanelian/godot-rand-utils

Supported Engine Version
3.2
Version String
0.2.0
License Version
MIT
Support Level
community
Modified Date
3 years ago
Git URL
Issue URL

Godot RandUtils

A collection of RNG (Random Number Generator) utilities for the Godot Engine.

Why?

I felt like I was missing RNG utilities while working on my game, so I started working on this addon, and kept adding methods others might need!

Features

This addon provides:

  • Random string generation
  • Random boolean with ability to specify probability
  • Random normalized Vec2 and Vec3
  • Random Color with customizable HSV ranges
  • Random item(s) from array
  • Random byte(s)

Installation

  1. Clone this repository into your project or, alternatively, use git submodule.
  2. Enable the addon in the project settings.

Usage

This addon provides a RandUtils class, which contains static methods used to generate data. As the methods are static, you don't have to instantiate the class.

## Returns a boolean based on a probability
static func bool(probability: float = .5) -> bool:
## Returns a normalized Vector2
static func vec2() -> Vector2:
## Returns a normalized Vector3
static func vec3() -> Vector3:
## Returns a random string containing letters with a given length
static func letters(length: int = 1, unique: bool = false) -> String:
## Returns a random string containing alphanumeric characters with a given length
static func alphanumeric(length: int = 1, unique: bool = false) -> String:
## Returns a random string containing alphanumeric characters with a given length. Letters are lowercase
static func alphanumeric_simple(length: int = 1, unique: bool = false) -> String:
## Returns a random string containing ASCII characters with a given length.
static func string(length: int = 1, unique: bool = false) -> String:
## Returns a random string from a given length and string characters
static func from_string(string, length: int = 1, unique: bool = false) -> String:
## Returns a Color instance with randomized properties
static func color(hueMin: float = 0, hueMax: float = 1, saturationMin: float = 0, saturationMax: float = 1, valueMin: float = 0, valueMax: float = 1, alphaMin: float = 1, alphaMax: float = 1) -> Color:
## Returns a random byte (int)
static func byte() -> int:
## Returns a PoolByteArray filled with n random bytes
static func byte_array(size: int = 1) -> PoolByteArray:
## Returns one or multiple random elements from an array
static func from_array(array: Array, num: int = 1, unique: bool = false) -> Array:

Examples

70% probability of having a boolean of value true

RandUtils.bool(.7)

Getting n elements from an array

var array = ["banana", "apple", "cherry", "cat"]
print(RandUtils.from_array(array, 2))

Output: ["apple", "cat"]

Licence

This addon is published under the MIT licence.

A collection of RNG (Random Number Generator) utilities for the Godot Engine.

This addon provides:

- Random string generation
- Random boolean with ability to specify probability
- Random normalized Vec2 and Vec3
- Random Color with customizable HSV ranges
- Random item(s) from array
- Random byte(s)

This addon provides a RandUtils class, which contains static methods used to generate data. As the methods are static, you don't have to instantiate the class.

Check the readme for more information, including usage: https://github.com/JulienVanelian/godot-rand-utils

Reviews

0 ratings

Your Rating

Headline must be at least 3 characters but not more than 50
Review must be at least 5 characters but not more than 500
Please sign in to add a review

Quick Information

0 ratings
RandUtils icon image
julienvanelian
RandUtils

A collection of RNG (Random Number Generator) utilities for the Godot Engine.This addon provides:- Random string generation- Random boolean with ability to specify probability- Random normalized Vec2 and Vec3- Random Color with customizable HSV ranges- Random item(s) from array- Random byte(s)This addon provides a RandUtils class, which contains static methods used to generate data. As the methods are static, you don't have to instantiate the class.Check the readme for more information, including usage: https://github.com/JulienVanelian/godot-rand-utils

Supported Engine Version
3.2
Version String
0.2.0
License Version
MIT
Support Level
community
Modified Date
3 years ago
Git URL
Issue URL

Open Source

Released under the AGPLv3 license

Plug and Play

Browse assets directly from Godot

Community Driven

Created by developers for developers