Random number question
Dazza006
Member Posts: 248
Hi could someone please share how you would get two random numbers.
In my new project I have 5 different colours,
0= pink
1= green
2= blue
3=yellow
4=orange
I'm trying to set up different combinations, I have (random) 0,4 0,3 0,2 0,1 but how would I get a random number for only (0) (3)
if I use the random expression "random 0,3" it would give me random numbers 0-3
I hope you understand what i'm asking I have used a way with tables on a previous project but there must be a simpler way
-Darren
In my new project I have 5 different colours,
0= pink
1= green
2= blue
3=yellow
4=orange
I'm trying to set up different combinations, I have (random) 0,4 0,3 0,2 0,1 but how would I get a random number for only (0) (3)
if I use the random expression "random 0,3" it would give me random numbers 0-3
I hope you understand what i'm asking I have used a way with tables on a previous project but there must be a simpler way
-Darren
Comments
Make two attributes, example: Number_1 and Number_2 then make an actor do a random(0-4) on both and you'll have two different values.
Change Attribute game.random to random(0,1)
When attribute game.random=0
.....Change Attribute game.theNumber to 0
Otherwise
.....Change Attribute game.theNumber to 3
If you wanted to choose 2 or 4, you would still use random(0,1) for a 50% probability of either number:
Change Attribute game.random to random(0,1)
When attribute game.random=0
.....Change Attribute game.theNumber to 2
Otherwise
.....Change Attribute game.theNumber to 4
You're probably getting tripped up by the fact that we're using random numbers to choose other numbers. If you thought of it with something else such as animals (or colors), it would be:
Change Attribute game.random to random(0,1)
When attribute game.random=0
.....Change Attribute game.theAnimal to cow
Otherwise
.....Change Attribute game.theAnimal to horse
It doesn't really matter what the actual values are (0, 3; 2, 4; cow, horse).
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Thats exactly what I was trying to explain.
Thanks for your help
-Darren
http://www.ezinterweb.com/2013/03/fisher-yates-in-place-shuffle-for_18.html
Your solution works perfectly for {0,3} but as soon as they want {2,3} they have to figure out a different formula.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Or if you just want it lay it out in tables,
tableCellValue(game.TableRandom,random(1,3),1)
Are you only allowed to tell us brilliant things on the forums once a day?
You seem to pop up and offer suggestions no one else does.
But seriously, if I offer suggestions someone else does, then it would be a waste of my time. (And your time for reading what someone already wrote)
Could someone please explain how I would get a random number 0-4
but missing out the 1 so
0,2,3,4. I cant seem to get my head round this lol ~X(
-- Change Attribute: self.myIndex To: random(1,4)
-- When self.myIndex = 1
----Change Attribute: self.myIndex To: 0
Thanks works a treat
Hi @Dazza006 From what I've read in your thread, this is something different you're asking now... So if I've understood you correctly, this'll work: make two integer attributes one called Temp and another called yourNumber.
Change attribute Temp to random(1,4)
When Temp = 1
Change attribute Temp to 0
Change attribute yourNum to Temp
Edit: @RThurman beat me to it... strange, I wasn't too long and yet there's half an hour difference... whatever!
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
Trying to get people to use the mod(x,y) instead of %.
Otherwise it would have been random(2,5)%5
@CodeMonkey -- are you indicating that operators like % and/or ^ are being depreciated in favor of functions like mod(x,y) and/or pow(x)? Or are you stating a simple preference? Or are you just feeling like its just a mod(x,y) kind of day?
@Dazza006 If you have a bunch of these random number scenarios ("well, what about 1 to 8 but not including 2 or 5?"), you might consider using a table instead.
Just put each of your possible values in a separate row, for example:
1
3
4
6
7
8
And then do:
Change Attribute game.randomRow to random(1,tableRowCount(tableName))
.....^^ the above behavior picks a random row of the table
Change Attribute game.randomPick to tableCellValue(tableName,randomRow,1)
.....^^ the above behavior returns the value of the cell in that row (at column 1)
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Good thinking from @tatiang there...
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
^ should already have been deprecated. I think. If not, it also is a lua thing.