This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-10-09 02:09:22

Micleah
New Scratcher
Registered: 2012-10-08
Posts: 3

Random Number Issue

I Need the script to pick a random number between either 20 and 160 or -20 and -160. Does anyone know how i can do this?

Offline

 

#2 2012-10-09 02:14:36

Micleah
New Scratcher
Registered: 2012-10-08
Posts: 3

Re: Random Number Issue

So that's between 160 and -160, excluding numbers between -20 and 20.

Offline

 

#3 2012-10-09 03:29:11

jontmy00
Scratcher
Registered: 2011-11-28
Posts: 1000+

Re: Random Number Issue

Here:

when gf clicked
broadcast [random v]

when I receive [random v]
set [variable v] to (pick random (-160) to (160))
if <<(variable) < [20]> and <(variable) > [-20]>>
broadcast [random v]
else
stop script
end

Last edited by jontmy00 (2012-10-09 03:29:56)


FOR ALL THE NEWS ON UPDATES FOR SIMPLISTICRAFT, CLICK HERE.

Offline

 

#4 2012-10-09 04:20:01

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: Random Number Issue

Better yet:

set [rand v] to (pick random (20) to (160))
if <(pick random (0) to (1)) = (1)>
set [rand v] to ((-1) * (rand))
end
say (rand)


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#5 2012-10-09 05:32:56

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Random Number Issue

Hardmath123 wrote:

Better yet:

set [rand v] to (pick random (20) to (160))
if <(pick random (0) to (1)) = (1)>
set [rand v] to ((-1) * (rand))
end
say (rand)

There's a more compact way:

set [random v] to ((pick random (20) to (160)) * (((pick random (0) to (1)) - (0.5)) * (2)))


http://i46.tinypic.com/35ismmc.png

Offline

 

#6 2012-10-09 05:50:29

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: Random Number Issue

ErnieParke wrote:

Hardmath123 wrote:

Better yet:

set [rand v] to (pick random (20) to (160))
if <(pick random (0) to (1)) = (1)>
set [rand v] to ((-1) * (rand))
end
say (rand)

There's a more compact way:

set [random v] to ((pick random (20) to (160)) * (((pick random (0) to (1)) - (0.5)) * (2)))

True, but it's harder to read/understand.


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#7 2012-10-09 05:52:27

jontmy00
Scratcher
Registered: 2011-11-28
Posts: 1000+

Re: Random Number Issue

^ You glitched the Scratch Blocks and now my web page looks horrible.  hmm


FOR ALL THE NEWS ON UPDATES FOR SIMPLISTICRAFT, CLICK HERE.

Offline

 

#8 2012-10-09 05:55:26

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: Random Number Issue

*gasp* BUG!


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#9 2012-10-09 05:57:03

jontmy00
Scratcher
Registered: 2011-11-28
Posts: 1000+

Re: Random Number Issue

Hardmath123 wrote:

*gasp* BUG!

It's a known bug. You did not close the [scratchblocks] tag, that's why.


FOR ALL THE NEWS ON UPDATES FOR SIMPLISTICRAFT, CLICK HERE.

Offline

 

#10 2012-10-09 06:06:28

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: Random Number Issue

Technically, the quotee didn't close the tag.  wink


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#11 2012-10-10 06:07:11

Micleah
New Scratcher
Registered: 2012-10-08
Posts: 3

Re: Random Number Issue

Thanks guys!  big_smile

Offline

 

Board footer