math.random function with step option?

Omar Ayman

A custom function that will return a random number with a step option available like in the for loop. Example:

for i=1,10,**2** do
   print(i)
end
Oliver

Do you mean this:

function randomWithStep(first, last, stepSize)
    local maxSteps = math.floor((last-first)/step)
    return first + stepSize * math.random(0, maxSteps)
end

This gives the same behavior as math.random(first, last) except that the values will be "stepSize" apart. Note that the highest random # may not be "last", depends if (last-first) is a multiple of stepSize.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

math.random function with step option?

From Dev

Why Math.random() type is number and Math.random is function?

From Dev

javascript TypeError: Math.random is not a function on chrome

From Java

Is a function that calls Math.random() pure?

From Dev

math.random function in lua to position object

From Dev

Math.random() javascript function *undefined* on Chrome

From Dev

math.random function in lua to position object

From Dev

Math.Random in function always the same result

From Dev

Math.random/floor with a function and onclick?

From Dev

how to create a java function that makes random math problems.

From Dev

how to find the appropriate math function for series with random numbers in Excel

From Dev

Why does Math.floor(Math.random()) function always return "0"?

From Dev

Is it possible for Math.random() === Math.random()

From Dev

Javascript Math.random() not *that* random…?

From Dev

Math.Random is not so random

From Dev

Random step generator

From Dev

Math.random not working

From Dev

Math & JavaScript | Random chances

From Dev

Arrays Random Multiplication Math

From Dev

Math.random Scenario

From Dev

When I execute a Math.random() function why is it able to return "1" when "1" is exclusive?

From Dev

insert math functions in math function

From Dev

How to understand --step option in RRD?

From Dev

Java Math.random() How random is it?

From Dev

Math.random number of random bits

From Dev

Java Math.random not random in while loop

From Dev

Math.Random() To pick random array

From Dev

Making Math.random() more random?

From Dev

Math.random number of random bits