# Random Help

**URL:** https://forum.kirupa.com/t/random-help/15249
**Category:** flash
**Created:** [March 12, 2003, 4:39am UTC](https://forum.kirupa.com/t/random-help/15249 "2003-03-12T04:39:22Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![BullDog\_Flash](https://avatars.discourse-cdn.com/v4/letter/b/d07c76/32.png) [@BullDog\_Flash](https://forum.kirupa.com/u/BullDog_Flash)
#### Post date: [March 12, 2003, 4:39am UTC](https://forum.kirupa.com/t/random-help/15249/1 "2003-03-12T04:39:22Z")

</div>

O.K

Random Isent hard i did it before.But one thing i forgot is to remember the code.And Understand it.

I want it so when my Player MC hits the Coin MC it goes to another spot randomly.

Code

```
    this._x = random(250);
    this._y = random(150);

```

Thats what i have.

But o dont want it to go off the screen

so i started experimenting dident have any sucess.

Experiment

```
    this._x = random(10,250);
    this._y = random(10,150);

```

So it should randomly go to a number from 10 to 250 dident have any sucess please please please help me.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [March 12, 2003, 4:45am UTC](https://forum.kirupa.com/t/random-help/15249/2 "2003-03-12T04:45:53Z")

</div>

try this

```auto

xRan = Math.round(Math.random()*Stage.width);
yRan = Math.round(Math.random()*Stage.width);
this._x = xRan - this._width;
this._y = yRan - this._height;

```

code is pretty self explanitory…

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [March 12, 2003, 4:48am UTC](https://forum.kirupa.com/t/random-help/15249/3 "2003-03-12T04:48:28Z")

</div>

I dont thknk that code would work.

I want it so it goes from like 10,250 on the stage.

Even though it dont work it would go all over the place.

I need it to go between 10 and lke 250.

Anyone else

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [March 12, 2003, 4:50am UTC](https://forum.kirupa.com/t/random-help/15249/4 "2003-03-12T04:50:53Z")

</div>

xRan = Math.round(Math.random()\*240);  
yRan = Math.round(Math.random()\*240);  
this.\_x = 10 + xRan;  
this.\_y = 10 + yRan;

there ya go.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [March 12, 2003, 4:53am UTC](https://forum.kirupa.com/t/random-help/15249/5 "2003-03-12T04:53:15Z")

</div>

O\>K seems alot easier than mine.

But to top it off.

What does Mathround mean.

Im not good with that type of stuff

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [March 12, 2003, 4:55am UTC](https://forum.kirupa.com/t/random-help/15249/6 "2003-03-12T04:55:00Z")

</div>

its rounds the number.

Math.random()\*240 gives you a number between 0 and 240 but it gives you 4 decimal points, so you would get 202.3489 or 12.9063

Math.round() rounds the number to the nearest whole number. Just use that to make sure your movieclip will be on a whole number because the lines work better and show up better when you use whole numbers.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [March 12, 2003, 4:58am UTC](https://forum.kirupa.com/t/random-help/15249/7 "2003-03-12T04:58:52Z")

</div>

Thanks alot Jubba.

Now all i have to do is my counter and im finished my Engine.Then ill fix up the graphics thanks alot again.
