Krosskode
|
  |
| Joined: 26 Aug 2010 |
| Total Posts: 11001 |
|
|
| 15 Jan 2015 11:26 PM |
I'm working on a basic random algorithm for my trivia game, and I use this:
local AnswerValues = { CurrQuestion.One, CurrQuestion.Two, CurrQuestion.Three, CurrQuestion.Four } while #AnswerValues > 0 do local AnswerValueIndex = math.random(1, #AnswerValues) local AnswerValue = AnswerValues[AnswerValueIndex] Event:FireClient(Guesser, AnswerValue.Name, AnswerValue.Value, AnswerValue.Correct.Value) table.remove(AnswerValues, AnswerValueIndex) end
Though it is different than the first result before I started working on this, it is never random, it remains in the same position. Is there anyway to make this more random? |
|
|
| Report Abuse |
|
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
|
| 15 Jan 2015 11:30 PM |
| AnswerValueIndex = AnswerValues[math.random(#AnswerValues)] |
|
|
| Report Abuse |
|
|
Krosskode
|
  |
| Joined: 26 Aug 2010 |
| Total Posts: 11001 |
|
| |
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
|
| 15 Jan 2015 11:32 PM |
its not the same, it changes pseudo randomly
yep i tested it |
|
|
| Report Abuse |
|
|
|
| 15 Jan 2015 11:33 PM |
Unless you are setting the seed multiple times and not showing us, that looks fine.
You could also do this table.sort(AnswerValues, function() return math.random() >= 0.5 end) and then fire the client with the results one by one. |
|
|
| Report Abuse |
|
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
|
| 15 Jan 2015 11:35 PM |
"ha he hi ho ho he ho hi ho hi he ho ha ho hi hi he hi ha he he he ha he hi ho he hi hi he he hi"
is the out put of this code:
AnswerValues = {"he","ha","ho","hi"} while true do AnswerValueIndex = AnswerValues[math.random(#AnswerValues)] print(AnswerValueIndex) wait(0.1) end
-- pseudo random |
|
|
| Report Abuse |
|
|
|
| 15 Jan 2015 11:38 PM |
| The thing is, chimmihc, that is the same functionally as his code was before, except you are using AnswerValueIndex when it is more correct to call it AnswerValue. |
|
|
| Report Abuse |
|
|
|
| 15 Jan 2015 11:40 PM |
| Its not that its not random. Its just your luck. It just happens that it always seems to be the same. |
|
|
| Report Abuse |
|
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
|
| 15 Jan 2015 11:40 PM |
| i was just editing his script, not making a new one for him |
|
|
| Report Abuse |
|
|
|
| 16 Jan 2015 12:08 AM |
| yeah ik dat. I was just saying it was random, and that he was unlucky cuz he kept getting the same question over and over again. |
|
|
| Report Abuse |
|
|
mustyoshi
|
  |
 |
| Joined: 27 Dec 2007 |
| Total Posts: 41651 |
|
|
| 16 Jan 2015 12:14 AM |
math.randomseed(tick())
~Monica |
|
|
| Report Abuse |
|
|