Documentation index for AI agents (llms.txt) A Markdown version of every page is available: request the page's source under /docs/, follow the "alternate" link in this page's head, or start from /llms.txt.
Visual Script logo Manual

Random Integer#

Random / Random Integer

  • Can Read

  • Cannot Write

Description#

Returns a random whole number between two values, both included

Parameters#

Name Description
Min The lowest value that can be returned
Max The highest value that can be returned

Code#

using System;
using UnityEngine;
using VisualScript.Icons;
using Random = UnityEngine.Random;

namespace VisualScript.Runtime
{
    [Get]

    [Title("Random Integer")]
    [Category("Random/Integer")]

    [Description("Returns a random whole number between two values, both included")]
    [Image(typeof(IconDice), ColorTheme.Type.Yellow, typeof(BadgeZ))]

    [Parameter("Min", "The lowest value that can be returned")]
    [Parameter("Max", "The highest value that can be returned")]

    [Keywords("Dice", "Range", "Whole", "Int", "Roll")]

    [Serializable]
    public class TypeNumberRandomInteger : TypeNumber
    {
        [SerializeField] private GetInteger m_Min = new GetInteger(0);
        [SerializeField] private GetInteger m_Max = new GetInteger(10);

        public override double Get(Args args)
        {
            int min = this.m_Min.GetInt(args);
            int max = this.m_Max.GetInt(args);

            return min <= max
                ? Random.Range(min, max + 1)
                : Random.Range(max, min + 1);
        }

        public override string ToString()
        {
            return $"Random Integer({this.m_Min}, {this.m_Max})";
        }

        protected override SubscriptionMode Subscription => SubscriptionMode.OnUpdate;
    }
}
Visual Script logoVisual Script © Catsoft Works 2026. All rights reserved.