
-----------------------------------
upthescale
Sun May 07, 2006 7:54 pm

`color
-----------------------------------
type balls:
record
col:int%%%%%%Color
end record

var...etc i dont feel liek typing it outlol

for i:1..10
randint(ball( i ).col,1,255)
end for


ok so my problem is this, my backgorund is black, how can i do it so all my balls are a random coklor between 1-255, but not black>?
because if they are black, u wont see them!!!!
i tried
randint(ball.(i).col ,1,255 not black) but obviously it iddnt werk!

-----------------------------------
Tony
Sun May 07, 2006 8:06 pm

Re: `color
-----------------------------------
randint(ball.(i).col ,1,255 not black) but obviously it iddnt werk!
Have you tried

Rand.Int(any colour but black) ? Maybe... oh wait, Turing is not a natural language, now is it?


ball(i).col := Rand.Int(black+1, 255)


-----------------------------------
jamonathin
Sun May 07, 2006 8:06 pm


-----------------------------------
First, take a good look at all of the colors

for i : 1 .. maxcolor
    color (i)
    put i, " " ..
end for


Then loop it until it fits right

while (color not= blackNumber)
     {
     color = randomNumber
     }


-----------------------------------
Cervantes
Sun May 07, 2006 8:08 pm

Re: `color
-----------------------------------
First, there's no point in making a variable type if it's just going to store a single field (and that field is a primitive data type).

Second, don't use 'randint'. Use 'Rand.Int'. Functions are so much nicer than procedures, especially for something like this. The 'randint' procedure takes your variable and gets full control of it. It can do whatever you want to it. Giving away this kind of access is not a good thing.

As for picking a random value that is not black, see To return to the original question for a moment, there's no need to have a loop. Why would you possibly want to use a loop to generate a second random number when you can do it on the first try?

Say the first roll is 6. The second roll must be one of the set {1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 12, 13}. There's 12 digits there. Thus, we can "roll a 12-sided die" and use that value. However, if the value on this roll is a 6, we return 13.


var n := 13

var d1 := Rand.Int (1, n)
var d2 := Rand.Int (1, n - 1)
if d2 = d1 then
    d2 := n
end if


-----------------------------------
upthescale
Sun May 07, 2006 8:13 pm


-----------------------------------
thx tony
