Skip to content

Santhosh Ponnam

Technology Blog

  • Home
  • About
  • Technology
    • Java
    • ORM
  • Privacy Policy
  • Toggle search form
  • JPA vs Hibernate – Specification Vs Implementation ORM
  • hashCode and equals methods in java Java
  • HikariCP Configurations – Database Connection Pooling Installations and Configurations
  • Setting Environment Variables in Windows Java
  • HikariCP Connection Pooling for Spring Boot for 1.x version Spring Boot
  • Log4J (RCE) Vulnerability Java
  • Another Log4j Bug – DoS Java
  • Fixing Log4j Vulnerability Java

Unique Random ‘N’ digit Number generator

Posted on August 12, 2016August 13, 2021 By Santhosh Ponnam No Comments on Unique Random ‘N’ digit Number generator
package com.santhosh.random;

import java.util.Random;

import org.apache.commons.lang3.StringUtils;

public class SequenceGenerator {
    private final Random random;

    public SequenceGenerator() {
        random = new Random();
    }

    /**
     * Returns a pseudo-random integer between 0 and n-1.
     *
     * @see Random#nextInt(int)
     */
    public int nextInt(int n) {
        return random.nextInt(n);
    }

    public static void main(String[] args) {
        SequenceGenerator g = new SequenceGenerator();
        String result = StringUtils.leftPad(String.valueOf(g.nextInt(99999)),
                5, '0');
        System.out.println(result);
    }
}
Java Tags:Java

Post navigation

Previous Post: Setting Environment Variables in Windows
Next Post: hashCode and equals methods in java

Related Posts

  • Why to have a private constructor? Java
  • Log4J (RCE) Vulnerability Java
  • Setting Environment Variables in Windows Java
  • Fixing Log4j Vulnerability Java
  • hashCode and equals methods in java Java
  • Log4j Vulnerability / Version Upgrade to 2.16.0 by Apache Team Java

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • Another Log4j Bug – DoS
  • Log4j Vulnerability / Version Upgrade to 2.16.0 by Apache Team
  • Fixing Log4j Vulnerability
  • Log4J (RCE) Vulnerability
  • JPA vs Hibernate – Specification Vs Implementation

Categories

  • Installations and Configurations
  • Java
  • ORM
  • Spring Boot
  • Spring Boot HikariCP Connection Pooling

Archives

  • December 2021
  • August 2021
  • November 2020
  • March 2020
  • August 2018
  • November 2016
  • August 2016

Recent Posts

  • Another Log4j Bug – DoS
  • Log4j Vulnerability / Version Upgrade to 2.16.0 by Apache Team
  • Fixing Log4j Vulnerability
  • Log4J (RCE) Vulnerability
  • JPA vs Hibernate – Specification Vs Implementation

Categories

  • Installations and Configurations
  • Java
  • ORM
  • Spring Boot
  • Spring Boot HikariCP Connection Pooling

Archives

  • December 2021
  • August 2021
  • November 2020
  • March 2020
  • August 2018
  • November 2016
  • August 2016




Recent Posts

  • Another Log4j Bug – DoS
  • Log4j Vulnerability / Version Upgrade to 2.16.0 by Apache Team
  • Fixing Log4j Vulnerability
  • Log4J (RCE) Vulnerability
  • JPA vs Hibernate – Specification Vs Implementation

Categories

  • Installations and Configurations
  • Java
  • ORM
  • Spring Boot
  • Spring Boot HikariCP Connection Pooling
  • Log4J (RCE) Vulnerability Java
  • Fixing Log4j Vulnerability Java
  • Why to have a private constructor? Java
  • hashCode and equals methods in java Java
  • Windows Commands – kill port number Installations and Configurations
  • JPA vs Hibernate – Specification Vs Implementation ORM
  • Sonar Qube – Code Coverage and Code Quality Tool Installations and Configurations
  • Log4j Vulnerability / Version Upgrade to 2.16.0 by Apache Team Java

Copyright © 2023 Santhosh Ponnam.

Powered by PressBook News WordPress theme