Press "Enter" to skip to content

Generate a Random Number Picker In Vanilla JavaScript

Random Number Picker is a Vanilla JS-based number picker that allows you to generate a random number within a specified range.

javascript random number between 1 and 10, generate random number javascript, basic javascript generate random whole numbers within a range

How to make use of it:

1. Create min/max input fields.

<input type="number" class="input-number" id="minValue" />
<input type="number" class="input-number" id="maxValue" />

2. Create a button to generate a random number.

<input type="submit" id="btn" onclick="pick()" value="Generate" />

3. Create a container to hold the end result.

<p id="result">Result</p>

4. The core JavaScript to allow the random quantity picker.

function pick() {
    var result = document.getElementById("result")
    var min = document.getElementById("minValue").value
    var max = document.getElementById("maxValue").value
    if (min && max) {
        if (min > max) {
            let n3 = min
            let n4 = max
            max = n3
            min = n4
        min = Math.ceil(min)
        max = Math.ceil(max) + 1
        resultFinal = Math.floor(Math.random() * (max - min)) + min
        result.innerHTML = resultFinal

Random Number Picker Plugin/GIthub, javascript random number between range

See Demo And Download

Official Website(devchazz): Click Here

This superior jQuery/javascript plugin is developed by devchazz. For extra Advanced Usages, please go to the official website.

Be First to Comment

    Leave a Reply

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