• 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
  • random

    Prev Next
    Processor
    Generate a random string that is a valid Java identifier

    Summary

    The random macro generates a random string that is guaranteed to be a valid Java identifier. The first character is always a letter, and subsequent characters are letters or numbers.

    Syntax

    ${random[;<length>]}
    

    Parameters

    • length (optional) - Number of characters to generate (default: 8)

    Behavior

    • Generates a random string of specified length
    • First character is always an ASCII letter (a-z, A-Z)
    • Subsequent characters are ASCII letters or numbers (a-z, A-Z, 0-9)
    • Result is always a valid Java identifier
    • Default length is 8 characters

    Examples

    Generate default 8-character identifier:

    ${random}
    # Returns: "aB3xY9kL" (example)
    

    Generate specific length:

    ${random;12}
    # Returns: "K5mPqR7sT2uV" (example, 12 chars)
    

    Create unique package name:

    test.package=${random;16}
    

    Generate unique property:

    temp.id.${random;6}=value
    

    Create unique class names:

    TestClass${random;4}
    

    Use Cases

    • Generating unique identifiers
    • Creating temporary package or class names
    • Generating random test data
    • Creating unique property keys
    • Avoiding naming conflicts
    • Temporary file or directory naming

    Notes

    • Output is always a valid Java identifier
    • First character is never a number
    • Uses only ASCII letters and numbers (no special characters)
    • Not cryptographically secure - don’t use for security purposes
    • Each invocation generates a new random value
    • See also: ${rand} for random numbers

    See test cases in MacroTestsForDocsExamples.java

Prev Next
Search
    • Home