Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411593 Posts in 69386 Topics- by 58444 Members - Latest Member: FightingFoxGame

May 07, 2024, 12:09:20 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Help with random();
Pages: [1]
Print
Author Topic: Help with random();  (Read 1445 times)
cyprien
Guest
« on: October 21, 2008, 07:10:02 PM »

The issue I'm currently facing is producing objects at random within certain boundaries.
Code:
For example: 288 > x < 32

I'm just not sure how to go about writing that out in GML. =\

So far for my create_instance is as follows:
Code:
instance_create(random(288), random(224), oMid);

Any help is appreciated. =)

Logged
moi
Level 10
*****


DILF SANTA


View Profile WWW
« Reply #1 on: October 21, 2008, 07:14:14 PM »

I don't know GML but this line doesn't seem correct
it should be something like

Code:
x = random(254)+33
Logged

subsystems   subsystems   subsystems
Matt Thorson
Level 7
**

c'est la vie


View Profile WWW
« Reply #2 on: October 21, 2008, 08:15:20 PM »

I don't know GML but this line doesn't seem correct
it should be something like

Code:
x = random(254)+33

Yeah, random() returns a real between 0 and the argument given.  Use this rule:

a + random( b - a )
a = left bound
b = right bound


so for 32 < x < 288:

32 + random( 288 - 32 )

or, simplified:

32 + random( 256 )
Logged

cyprien
Guest
« Reply #3 on: October 22, 2008, 03:45:54 AM »

Thanks you guys, that did the trick. =)
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic