1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

roblox,luaで正規乱数をつくる

Posted at

はじめに

robloxおよびluaには一様乱数math.randomは用意されていますが、正規乱数が用意されていません。
そこで、一様乱数から正規乱数を生成する関数を定義しました。

参考

ボックス=ミュラー法
Javascriptで正規分布

コード

local function randn()
	xx = math.random()
	yy = math.random()
	
	zz = math.sqrt(-2*math.log(xx))*math.cos(2*math.pi*yy)
	return zz
end

最後に

image.png

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?