|
| 12 Jun 2012 10:00 PM |
Currently I have one that uses LCG, but there's a few problems:
- I don't know how to add an effective minimum to Random - It sometimes has a short period (i.e. it goes 4,3,2,1,4,3,2,1,4,3,2 when you do Random(4)) - It sometimes repeats (i.e. 3,3,3,3,3,3,3,3,3)
local Cur = 0 local Results = {} function SetSeed(seed) Results = {[0] = math.floor(seed)} for i = 0, 100 do Results[i + 1] = (1.3.4.7.7.5.8.1.3 * Results[i] + 1) % 4.2.9.4.9.6.7.2.9.6 //ignore the .s, dumb filter end end function Random(Max) Cur = Cur + 1 return (Results[Cur] % Max) + 1 end
Any ways to make it better? |
|
|
| Report Abuse |
|
|
pwnedu46
|
  |
| Joined: 23 May 2009 |
| Total Posts: 7534 |
|
|
| 12 Jun 2012 10:17 PM |
"I don't know how to add an effective minimum to Random"
return (Results[Cur] % Max) + 1 + minimum
---------- ~pwnedu46, wiki writer~ |
|
|
| Report Abuse |
|
|
|
| 12 Jun 2012 10:20 PM |
| Quite embarrassing how I couldn't think of something simple as that..... |
|
|
| Report Abuse |
|
|
|
| 12 Jun 2012 10:23 PM |
| Wait, that doesn't seem right... |
|
|
| Report Abuse |
|
|
|
| 12 Jun 2012 10:26 PM |
Yeah, That's not right, I tried doing random numbers between 3 and 5 and got this:
5 6 4 8 7 7 6 8 4 5 |
|
|
| Report Abuse |
|
|
pwnedu46
|
  |
| Joined: 23 May 2009 |
| Total Posts: 7534 |
|
|
| 12 Jun 2012 11:13 PM |
| return (Results[Cur] % (Max-minimum)) + 1 + minimum |
|
|
| Report Abuse |
|
|
rayoma
|
  |
| Joined: 13 Nov 2009 |
| Total Posts: 1911 |
|
| |
|
rayoma
|
  |
| Joined: 13 Nov 2009 |
| Total Posts: 1911 |
|
|
| 13 Jun 2012 12:42 AM |
| Nevernind, I didn't realize your function wouldn't return a number between 0 and 1 like most random functions. Just use math.sin(math.exp(seed)). Works a lot easier, better and makes a lot more sense. |
|
|
| Report Abuse |
|
|