Computer Science Canada

How do you randomize pictures?

Author:  Wintermini [ Sat Jan 09, 2010 3:36 pm ]
Post subject:  How do you randomize pictures?

Initially I wanted to randomize strings... but I don't think it's possible. This is actually for a multiple question, but I can do the button wait procedure or something so I'll let the user click on the answer.

Author:  TheGuardian001 [ Sat Jan 09, 2010 4:11 pm ]
Post subject:  Re: How do you randomize pictures?

You do randomized pictures the same way you do randomized strings.

first, store all the possibilities in an array:
Turing:


var myPics : array 1 .. 10 of int

myPics(1) := Pic.FileNew("mypic.jpg")
...
myPics(10) := Pic.FileNew("myPic10.jpg")


Then generate a random number to decide what picture to display:

Turing:

var tmp : int := Rand.Int(1,10)
Pic.Draw(myPics(tmp),x,y,picMode)


The same can be done with strings by changing the array into a string and replacing Pic.Draw with put.

Author:  Wintermini [ Sat Jan 09, 2010 4:20 pm ]
Post subject:  RE:How do you randomize pictures?

OMG THANK YOU!!!

Author:  saranya [ Thu Jan 14, 2010 9:20 pm ]
Post subject:  RE:How do you randomize pictures?

can u help me with making my pictures not repeat

Author:  Carey [ Thu Jan 14, 2010 10:35 pm ]
Post subject:  RE:How do you randomize pictures?

You would have to store all previous numbers in an array, then when you pick a number, check the array to make sure it hasn't been picked before. Alternatively, you could take your array of pictures and do a bunch of random swapping to mix the order up, then use a for loop to display them from 1 to 10

Author:  TheGuardian001 [ Thu Jan 14, 2010 10:38 pm ]
Post subject:  Re: RE:How do you randomize pictures?

saranya @ Thu Jan 14, 2010 9:20 pm wrote:
can u help me with making my pictures not repeat


No, because I have no idea what you mean by that. Care to elaborate?


: