Skip to content
Yu's Blog

Yu's Blog

Welcome to my blog

Tag: the highest number we can get is max. Let’s see this same pattern repeated with Random#nextInt in the next section.

Posted on December 2, 2020

How to get random number in a range in Java

Let’s use the Math.random method to generate a random number in a given range: public int getRandomNumber(int min, int max) { return (int) ((Math.random() * (max – min)) + min); } Why does that work? Well, let’s look at what happens when Math.random returns 0.0, it’s the lowest possible output: 0.0 * (max – min) …

Continue reading “How to get random number in a range in Java”

CONTACT ME

My GitHub
My LinkedIn

Recent Posts

  • Enable Spring Boot Devtools in IntelliJ
  • Algorithm Pattern – Island Programs LC 200 1254 1020 695 1905 694
  • Algorithm Pattern – Binary Search
  • Algorithm Pattern – Sliding Window
  • Algorithm Pattern – Rotate & Spiral Array (LC 48 54 59)

Categories

  • Algorithm
  • Android
  • Architecture
  • AWS
  • BlockChain
  • DigitalCurrency
  • Docker
  • Flutter
  • Git
  • Go
  • Java
  • JavaScript
  • Kotlin
  • LambdaCalculus
  • Mac
  • Machine Learning
  • Networking
  • OS
  • Python
  • Server
  • Spring
  • Tool
  • Unity
  • Unreal
  • Vim
  • VSCode
  • Windows
  • WordPress

Tags

  • Algorithm
  • Android Studio
  • AndroidStudio
  • Array
  • AWS
  • BackTracking
  • BFS
  • Binary Search
  • Bit Manipulation
  • Blog
  • BST
  • Comparator
  • DFS
  • DynamicProgramming
  • Express
  • Firebase
  • Flutter
  • git
  • GitHub
  • HashMap
  • Integer
  • Java
  • JavaScript
  • Kotlin
  • LaserDefender
  • LeetCode
  • LinkedList
  • List
  • Mac
  • Node.js
  • OperatingSystem
  • Recursion
  • Server
  • SideProject
  • Sorting
  • Spring
  • Spring Boot
  • String
  • Tree
  • Unity
  • VPN
  • VPS
  • Vultr
  • Wechat
  • Windows
June 2022
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
27282930  
« May    

Meta

  • Register
  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org