How to create random integer between 1000-2000

Alpays

  • Newbie
  • Posts: 15

umar4911

  • Hero Member
  • Creating own server!
  • Posts: 513
Re: How to create random integer between 1000-2000
« Reply #1,  »
Quote from EK.IceFlake on February 6th, 2015, 05:16 AM
Hi, guys! After a bit of number-quenching and guesswork, I finally came up with my function that takes a random number from rand() and does some maths to make the from and to function work! It supports negative numbers, too. And also a mixture of negative and positive.
Here is the code:
Code: [Select]
function Random(from, to) return (rand()*(to+1-from)) / (RAND_MAX+1)+from;
Purely tested.
Hope you like it!
Code: [Select]
local n = Random(1000, 2000)
I am gamer, programmer and hacker. Try to find me!
xD

Alpays

  • Newbie
  • Posts: 15