• Intro Headers Instructions Macros Commands
Fork me on GitHub
    • Getting Started
      • Introduction
      • How to install bnd
      • Guided Tour Workspace & Projects
      • bnd / bndlib Features and JAR Wrapping Techniques
      • FAQ - Frequently Asked Questions
    • Concepts and Practices
      • Concepts
      • Background
      • Best practices
    • Build and Development
      • Build
      • Generating JARs
      • Versioning
      • Baselining
      • Service Components
      • Metatype
      • Contracts
      • Bundle Annotations
      • Accessor Properties
      • SPI Annotations
    • Dependency and Launching
      • Resolving Dependencies
      • Launching
      • Startlevels
    • Testing
      • Testing
      • Testing with Launchpad
    • Packaging and Distribution
      • Packaging Applications
      • JPMS Libraries
      • Wrapping Libraries to OSGi Bundles
    • Documentation and Tools
      • Generating Documentation
      • bnd CLI Commands
      • For Developers
      • Templates for Workspaces
      • Tips for Windows users
      • Tools bound to bnd
    • Reference Material
      • Reference
      • Headers
      • Instruction Reference
      • Instruction Index
      • Macro Reference
      • Macro Index
      • Plugins
      • External Plugins
    • Configuration and Troubleshooting
      • Settings
      • Errors
      • Warnings
  • rand (';' MIN ' (;' MAX )?)?

    Prev Next
    Macro
    Generate a random number within a specified range

    Summary

    The rand macro generates a random integer. By default it returns a number between 0 and 100, or within a specified min/max range (inclusive).

    Syntax

    ${rand[;<max>[;<min>]]}
    

    Parameters

    • max (optional) - Maximum value (default: 100)
    • min (optional) - Minimum value (default: 0)

    Behavior

    • No arguments: Random number 0-100
    • One argument: Random number 0 to max
    • Two arguments: Random number min to max
    • Range is inclusive (includes both min and max)
    • Returns rounded integer

    Examples

    Default range (0-100):

    ${rand}
    # Returns: 42 (example)
    

    Custom max:

    ${rand;10}
    # Returns: 7 (between 0-10)
    

    Custom range:

    ${rand;100;50}
    # Returns: 73 (between 50-100)
    

    Generate unique build number:

    build.number=${rand;9999;1000}
    

    Use Cases

    • Generating random test data
    • Creating unique identifiers
    • Random selection
    • Build numbers
    • Temporary values

    Notes

    • Range is inclusive on both ends
    • Returns integer (rounded)
    • Not cryptographically secure
    • Each invocation generates new value
    • See also: ${random} for random strings

    See test cases in MacroTestsForDocsExamples.java

Prev Next
Search
    • Home