Skip to content

proposal: math/rand/v2: Add IntInRange function #63880

@hrtsegv

Description

@hrtsegv

Proposal

This proposal suggests adding a new function, IntInRange(low, high int) int, to the math/rand package.
The function generates random integers within a specified range [low, high).

Function Implementation

func IntInRange(low, high int) int {
    return rand.Intn(high-low) + low
}

Rationale

  • It simplifies random integer generation within a specific range, making it easier especially for beginners.
  • Provides a clean and concise code for this common task.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Incoming

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions