Selecting a number randomly with math.random()

S Khurana

I want to select a random number within a range, but say number that gets generated is 'x', next time I want the number to be at least x±20. How can I achieve this?

math.random() takes only two parameters, So if in turn 1, the number that was selected is 40, in second it should be 50 or more/30 or less, and similarly next time it should be 60 or more/20 or less.

jcaron

Don't know LUA, so we'll go for pseudocode

t = Math.random(0,60);
if (t > last_value - 20)
    t += 40
last_value = t

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Selecting a number randomly with math.random()

From Dev

Simplest way to prevent math.random form selecting the same number twice (AS3)

From Dev

StackOverflowError in Math.Random in a randomly recursive method

From Dev

Selecting randomly a subset of a large number samples in Matlab

From Dev

Math.random number of random bits

From Dev

Math.random number of random bits

From Dev

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

From Dev

Randomly Disappearing Text Effect - Selecting Random Divs Using jQuery

From Dev

Selecting a random number within a series(python)

From Java

Is 161803398 A 'Special' Number? Inside of Math.Random()

From Dev

how to make Math.random round to a number

From Dev

How to Print Random number in a Math Table?

From Dev

Math.round (), How to with a random number?

From Dev

Math.random() Generates same number

From Dev

From randomly to not randomly selecting columns

From Dev

Random number generated and divided in to 3 numbers randomly in php

From Dev

Python: random choice on matrix without selecting the number on the same line

From Dev

Selecting Randomly within an Array

From Dev

Randomly selecting a function

From Dev

Randomly Selecting In EarlGrey

From Dev

How to make a random number math quiz with 10 questions in C++?

From Dev

Why JavaScript Math.random() returns same number multiple times

From Dev

Randomly generating math questions

From Dev

Randomly generating math questions

From Dev

If there a difference between int number = (int) (Math.random() * 1000); and int number = (int)(100 + Math.random() * 900);

From Dev

How do you generate a random number with equal probability using Math.random() in Java

From Dev

Getting same number when using Math.random() and ThreadLocalRandom.current().nextDouble() and Random class nextDouble() method?

From Dev

How do you generate a random number with equal probability using Math.random() in Java

From Dev

randomly selecting rows with header intact

Related Related

  1. 1

    Selecting a number randomly with math.random()

  2. 2

    Simplest way to prevent math.random form selecting the same number twice (AS3)

  3. 3

    StackOverflowError in Math.Random in a randomly recursive method

  4. 4

    Selecting randomly a subset of a large number samples in Matlab

  5. 5

    Math.random number of random bits

  6. 6

    Math.random number of random bits

  7. 7

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

  8. 8

    Randomly Disappearing Text Effect - Selecting Random Divs Using jQuery

  9. 9

    Selecting a random number within a series(python)

  10. 10

    Is 161803398 A 'Special' Number? Inside of Math.Random()

  11. 11

    how to make Math.random round to a number

  12. 12

    How to Print Random number in a Math Table?

  13. 13

    Math.round (), How to with a random number?

  14. 14

    Math.random() Generates same number

  15. 15

    From randomly to not randomly selecting columns

  16. 16

    Random number generated and divided in to 3 numbers randomly in php

  17. 17

    Python: random choice on matrix without selecting the number on the same line

  18. 18

    Selecting Randomly within an Array

  19. 19

    Randomly selecting a function

  20. 20

    Randomly Selecting In EarlGrey

  21. 21

    How to make a random number math quiz with 10 questions in C++?

  22. 22

    Why JavaScript Math.random() returns same number multiple times

  23. 23

    Randomly generating math questions

  24. 24

    Randomly generating math questions

  25. 25

    If there a difference between int number = (int) (Math.random() * 1000); and int number = (int)(100 + Math.random() * 900);

  26. 26

    How do you generate a random number with equal probability using Math.random() in Java

  27. 27

    Getting same number when using Math.random() and ThreadLocalRandom.current().nextDouble() and Random class nextDouble() method?

  28. 28

    How do you generate a random number with equal probability using Math.random() in Java

  29. 29

    randomly selecting rows with header intact

HotTag

Archive