Not very random

Blitz3D Forums/Blitz3D Beginners Area/Not very random

Wotcha, folks.

Can anyone tell me why the following code:
Graphics 800,600,32,2

SetBuffer BackBuffer()

SeedRnd MilliSecs

Type particle
	Field x,y
	Field angle
	Field red,green,blue
End Type

; MAIN LOOP
While Not KeyHit(1)
	
	Cls
	If MouseDown(1) Then boom
	updateboom
	Flip
	
Wend
End



Function boom()
	For f=1 To 10
		part.particle = New particle
		part\x=MouseX()
		part\y=MouseY()
		part\angle=Rnd(360)
		part\red=Rnd(255)
		part\green=Rnd(255)
		part\blue=Rnd(255)
	Next
End Function


Function updateboom()
	For part.particle = Each particle
		part\x=part\x + Cos(part\angle)*4
		part\y=part\y + Sin(part\angle)*4
		Color (part\red),(part\green),(part\blue)
		Rect part\x,part\y,4,4
		If part\x > 800 Or part\x<0 Or part\y>600 Or part\y<0 Then Delete part
	Next
End Function


Produces an 'ordered' sun-ray effect when the mouse button is held down?

Shouldn't my SEEDRND MILLISECS and PART\ANGLE=RND(360) produce a more .......random effect?

Much ta for any help.

Tobo.

Hi Tobo.

Take the SeedRnd out of the top part of the program, and put it into function boom() like so:

Function boom()
	For f=1 To 10
		SeedRnd MilliSecs()

		part.particle = New particle
		part\x=MouseX()
		part\y=MouseY()
		part\angle=Rnd(360)
		part\red=Rnd(255)
		part\green=Rnd(255)
		part\blue=Rnd(255)
	Next
End Function


seedrnd millisecs()

What tonyg said. Without the brackets (indicating a function) blitz thinks 'millisecs' is a variable holding zero, so it's equivalent to 'SeedRnd 0'.

That is correct.
Millisecs needs the brackets after it, but it still won't work unless it is put into the For loop inside function boom.

I think.

Not really. Reseeding might give more random results but the single seedrnd at the top should be good enough for most things.

Hi, guys. Thanks for your help.

Apparently it was my use of integers, rather than floats.

Giving the types PART\X, PART\Y and PART\ANGLE a # seems to do the trick.

This was answered for me by someone on the CW.com website. May I ask what people's views are about crossposting between here and there, as i don't really want to annoy anyone if doing so!

Many thanks,

Tobo.