Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Generating random numbers from a normal distribution and ...

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Dr.Disrespect
Grandmaster Cheater
Reputation: 3

Joined: 17 Feb 2016
Posts: 526

PostPosted: Fri Apr 21, 2017 3:00 pm    Post subject: Generating random numbers from a normal distribution and ... Reply with quote

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. Very Happy
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Fri Apr 21, 2017 4:59 pm    Post subject: This post has 2 review(s) Reply with quote

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
Back to top
View user's profile Send private message
Dr.Disrespect
Grandmaster Cheater
Reputation: 3

Joined: 17 Feb 2016
Posts: 526

PostPosted: Fri Apr 21, 2017 5:19 pm    Post subject: Reply with quote

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. Very Happy

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

A simple example is better then ten links. Very Happy
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 198

Joined: 25 Jan 2006
Posts: 8516
Location: 127.0.0.1

PostPosted: Fri Apr 21, 2017 7:56 pm    Post subject: Reply with quote

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

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Dr.Disrespect
Grandmaster Cheater
Reputation: 3

Joined: 17 Feb 2016
Posts: 526

PostPosted: Fri Apr 21, 2017 10:30 pm    Post subject: Reply with quote

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


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

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

A simple example is better then ten links. Very Happy
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 218

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

PostPosted: Sat Apr 22, 2017 6:49 am    Post subject: This post has 1 review(s) Reply with quote

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)

_________________
Back to top
View user's profile Send private message MSN Messenger
Dr.Disrespect
Grandmaster Cheater
Reputation: 3

Joined: 17 Feb 2016
Posts: 526

PostPosted: Sat Apr 22, 2017 12:23 pm    Post subject: Reply with quote

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. Very Happy +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. Very Happy
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites