Minecraft Wiki
Maxtal62 (обговорення | внесок)
(Сторінка очищена)
Мітка: Очищення
BabylonAS (обговорення | внесок)
(Скасування редагування № 7920 користувача Maxtal62 (обговорення))
Мітка: Скасування
 
Рядок 1: Рядок 1:
  +
local p = {}
  +
local seeded
  +
local randomseed = math.randomseed
  +
local random = math.random
  +
  +
function p.random( m, n )
  +
if not seeded then
  +
p.seed()
  +
end
  +
  +
return random( n and m or m and 1 or 0, n or m or 1 )
  +
end
  +
  +
function p.seed( seed )
  +
randomseed( seed or ( os.time() + os.clock() * 1000000000 ) )
  +
  +
-- First few values of seed is not guaranteed to be random on some platforms
  +
random()
  +
random()
  +
  +
seeded = true
  +
end
  +
  +
return p

Поточна версія на 13:04, 23 грудня 2018

This module generates a pseudo-random number. It is used the same as math.random, however it first sets up a seed so that the number is actually random.

local p = {}
local seeded
local randomseed = math.randomseed
local random = math.random

function p.random( m, n )
	if not seeded then
		p.seed()
	end
	
	return random( n and m or m and 1 or 0, n or m or 1 )
end

function p.seed( seed )
	randomseed( seed or ( os.time() + os.clock() * 1000000000 ) )
	
	-- First few values of seed is not guaranteed to be random on some platforms
	random()
	random()
	
	seeded = true
end

return p