2 registered members (NnamueN, 1 invisible),
1,489
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Random() not random?
#233710
10/30/08 00:57
10/30/08 00:57
|
Joined: Oct 2008
Posts: 22
SamstaUK
OP
Newbie
|
OP
Newbie
Joined: Oct 2008
Posts: 22
|
I Have been using the following code to randomly generate tornadoes on my map: var count = 1; while(count<(random(10))){ ent_create("tornado.mdl",vector(random(20000),random(20000),0),tornado); count = count + 1; } The problem is that they are in the same place each time? What am I doing wrong?
|
|
|
Re: Random() not random?
[Re: SamstaUK]
#233711
10/30/08 01:01
10/30/08 01:01
|
Joined: Oct 2008
Posts: 67
pewpew
Junior Member
|
Junior Member
Joined: Oct 2008
Posts: 67
|
random in computers usually isnt random. you need to set the random seed first i'd assume. i am new to c-lite but do a fair bit of c++.
go through the manual and search for random seed, then set it to the hours/minutes/seconds of the system clock. always works great.
something like: srand(clock.seconds) etc.
just once, at the start of your program
HURRR DERP DERP DEERRPP HURR
|
|
|
Re: Random() not random?
[Re: SamstaUK]
#233806
10/30/08 18:55
10/30/08 18:55
|
Joined: Aug 2008
Posts: 218 U.S.
GamerX
Member
|
Member
Joined: Aug 2008
Posts: 218
U.S.
|
I use random(100); for example which would be 0-100 or random(100)50; 50-100 works fine for me; If your doing it in a comparison try doing like var r;
while(1){
r = random(100); wait(1);
while(example > r)
{
blahblahblah wait(1);}
"You may never know what results come of your action, but if you do nothing there will be no result." -Mahatma Gandhi
|
|
|
Re: Random() not random?
[Re: GamerX]
#233835
10/30/08 21:15
10/30/08 21:15
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
Sorry, thought you we're using lite-c not c-script. When using c-script you should use randomize(). Be carefull random(100) does not return random numbers from 0 - 100 but from 0 - 99.999.
Always learn from history, to be sure you make the same mistakes again...
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|