generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Never random?

Previous Thread :: Next Thread 
Krosskode is not online. 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 is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
15 Jan 2015 11:30 PM
AnswerValueIndex = AnswerValues[math.random(#AnswerValues)]
Report Abuse
Krosskode is not online. Krosskode
Joined: 26 Aug 2010
Total Posts: 11001
15 Jan 2015 11:31 PM
Same result.
Report Abuse
chimmihc is not online. 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
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
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 is not online. 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
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
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
SilverArgentum is not online. SilverArgentum
Joined: 01 Nov 2011
Total Posts: 1162
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 is not online. 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
SilverArgentum is not online. SilverArgentum
Joined: 01 Nov 2011
Total Posts: 1162
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 is not online. mustyoshi
Top 50 Poster
Joined: 27 Dec 2007
Total Posts: 41651
16 Jan 2015 12:14 AM
math.randomseed(tick())

~Monica
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image