Cheat Engine
The Official Site of Cheat Engine

Author Message
Dr.Disrespect
Master Cheater
Reputation: 1

Joined: 17 Feb 2016
Posts: 473

 Posted: Fri Apr 21, 2017 3:00 pm    Post subject: Generating random numbers from a normal distribution and ... In CE Lua, how to generate random numbers from a normal distribution with a mean = 100 and standard deviation = 10? Is it possible? Thanks in advance. _________________************** A simple example is better then ten links.
Zanzer
I post too much
Reputation: 119

Joined: 09 Jun 2013
Posts: 3217

Posted: Fri Apr 21, 2017 4:59 pm    Post subject:

 Code: local list = {} local mean = 100 local stdDev = 10 for i = 1, 100 do   list[i] = mean + math.sqrt(-2 * math.log(math.random())) * math.cos(2 * math.pi * math.random()) * stdDev end
Dr.Disrespect
Master Cheater
Reputation: 1

Joined: 17 Feb 2016
Posts: 473

Posted: Fri Apr 21, 2017 5:19 pm    Post subject:

Zanzer wrote:
 Code: local list = {} local mean = 100 local stdDev = 10 for i = 1, 100 do   list[i] = mean + math.sqrt(-2 * math.log(math.random())) * math.cos(2 * math.pi * math.random()) * stdDev end

Thanks as always, Zanzer. +Rep.
I should've chosen math as my major.

_________________
**************

A simple example is better then ten links.
atom0s
Moderator
Reputation: 135

Joined: 25 Jan 2006
Posts: 7125
Location: 127.0.0.1

 Posted: Fri Apr 21, 2017 7:56 pm    Post subject: Is another example: https://rosettacode.org/wiki/Statistics/Normal_distribution#Lua _________________- Retired.
Dr.Disrespect
Master Cheater
Reputation: 1

Joined: 17 Feb 2016
Posts: 473

Posted: Fri Apr 21, 2017 10:30 pm    Post subject:

 atom0s wrote: Is another example: https://rosettacode.org/wiki/Statistics/Normal_distribution#Lua

Thanks a lot, atom0s. I will +Rep when I can.

_________________
**************

A simple example is better then ten links.
mgr.inz.Player
I post too much
Reputation: 146

Joined: 07 Nov 2008
Posts: 4132
Location: W kraju nad Wisla. UTC+01:00

Posted: Sat Apr 22, 2017 6:49 am    Post subject:

Just curious. For what type of cheat you needed it?

Edit:
to add something from myself, here is Marsaglia polar method:

 Code: marsagliapolar = {} function marsagliapolar:init()   math.randomseed(os.time())   self.isSpareReady = false end function marsagliapolar:random(mean,stdDev)   if self.isSpareReady then     self.isSpareReady = false     return self.spare*stdDev + mean   end   local U,V,mul   repeat     U,V = 2*math.random()-1, 2*math.random()-1     S = U^2+V^2   until (S~=0) and (S<=1)   self.isSpareReady = true   mul=(-2*math.log(S)/S)^0.5   self.spare = V*mul   return U*mul*stdDev + mean end

Usage:
 Code: marsagliapolar:init()  -- do it once or when you want to reset random generator with new seed value1 = marsagliapolar:random(average, variance^0.5) value2 = marsagliapolar:random(average, stdDev)

_________________
Dr.Disrespect
Master Cheater
Reputation: 1

Joined: 17 Feb 2016
Posts: 473

Posted: Sat Apr 22, 2017 12:23 pm    Post subject:

mgr.inz.Player wrote:
Just curious. For what type of cheat you needed it?

Edit:
to add something from myself, here is Marsaglia polar method:

 Code: marsagliapolar = {} function marsagliapolar:init()   math.randomseed(os.time())   self.isSpareReady = false end function marsagliapolar:random(mean,stdDev)   if self.isSpareReady then     self.isSpareReady = false     return self.spare*stdDev + mean   end   local U,V,mul   repeat     U,V = 2*math.random()-1, 2*math.random()-1     S = U^2+V^2   until (S~=0) and (S<=1)   self.isSpareReady = true   mul=(-2*math.log(S)/S)^0.5   self.spare = V*mul   return U*mul*stdDev + mean end

Usage:
 Code: marsagliapolar:init()  -- do it once or when you want to reset random generator with new seed value1 = marsagliapolar:random(average, variance^0.5) value2 = marsagliapolar:random(average, stdDev)

Thanks for the example and the math course, mgr.inz.Player. +Rep

It's a game like Football Manager where there are lots of AI players in the game. I want to randomly create some players per season, so the game will be more interesting and unpredictable, thats why I need to generate these numbers. The numbers are the attributes of each player. With a normal distribution, the abilities of the created players will be more reasonable, there won't be nine Michael Jordans out of ten players.

_________________
**************

A simple example is better then ten links.
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First
 All times are GMT - 6 Hours Page 1 of 1

 Jump to: Select a forum Cheat Engine----------------Cheat EngineCheat Engine Lua ScriptingCheat Engine TutorialsGeneral GamehackingAuto Assembler tutorialsPointer tutorialsGame specific tutorialsWebbrowser stuff related tutorialsConsole ModdingLUA TutorialsLua Extensions General Discussions----------------General DiscussionsArtComputer TalkRandom spamArt RequestsArt TutorialsWillekeurige RotzooiGuestsHorse Excrement Cheat Requests----------------Single player cheat request Cheat Engine Downloads----------------TablesTrainersAuto Assemble scripts Coding----------------Cheat Engine SourceCETC Server and ClientsDBVMPlugin developmentGeneral programmingBinariesCrackmesGeneral programming+Game Development2D Graphics3D ModelingGameplay designWeb Development Games----------------Flash GamesGaia OnlineStick Arena
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum