Discuss Scratch

blakelarson19
Scratcher
24 posts

Pick number a or number b?

For my program I need the computer to pick a random number for my generator, but For certain instances I don't want it to pick a random number from 1 to 10, but rather I want it to pick randomly two numbers that are not right next to each other… ie. 3 or 5 … 7 or 9 … 1 or 6. Please help?
jokebookservice1
Scratcher
1000+ posts

Pick number a or number b?

I don't quite understand. You can type whatever you want into the pick random block:
pickrandom3to5
Am I missing something?
piggiety
Scratcher
65 posts

Pick number a or number b?

Oh! I get it. This might work:

whenclickedsetrandomizertopickrandom1to10addrandomizertolistmoverandomizerstepssetrandomizertopickrandom1to10repeatuntilnotrandomizer=item1oflist+1orrandomizer=item1oflist-1ifrandomizer=item1oflist+1thensetrandomizertopickrandom1to10ifrandomizer=item1oflist-1thensetrandomizertopickrandom1to10moverandomizersteps

This is super complicated, but I hope it helps! I didn't know what the numbers were used for, so I just put in a bunch of move … steps. You can get rid of those if you want.
blakelarson19
Scratcher
24 posts

Pick number a or number b?

piggiety wrote:

Oh! I get it. This might work:

whenclickedsetrandomizertopickrandom1to10addrandomizertolistmoverandomizerstepssetrandomizertopickrandom1to10repeatuntilnotrandomizer=item1oflist+1orrandomizer=item1oflist-1ifrandomizer=item1oflist+1thensetrandomizertopickrandom1to10ifrandomizer=item1oflist-1thensetrandomizertopickrandom1to10moverandomizersteps

This is super complicated, but I hope it helps! I didn't know what the numbers were used for, so I just put in a bunch of move … steps. You can get rid of those if you want.

Thank you for the help, but I don't really understand this lol.
blakelarson19
Scratcher
24 posts

Pick number a or number b?

jokebookservice1 wrote:

I don't quite understand. You can type whatever you want into the pick random block:
pickrandom3to5
Am I missing something?

Yes, I don't want it to pick 3 to 5 I want it to pick 3 OR 5 , so I want 4 out of the picture completely.
piggiety
Scratcher
65 posts

Pick number a or number b?

blakelarson19 wrote:

piggiety wrote:

Oh! I get it. This might work:

whenclickedsetrandomizertopickrandom1to10addrandomizertolistmoverandomizerstepssetrandomizertopickrandom1to10repeatuntilnotrandomizer=item1oflist+1orrandomizer=item1oflist-1ifrandomizer=item1oflist+1thensetrandomizertopickrandom1to10ifrandomizer=item1oflist-1thensetrandomizertopickrandom1to10moverandomizersteps

This is super complicated, but I hope it helps! I didn't know what the numbers were used for, so I just put in a bunch of move … steps. You can get rid of those if you want.

Thank you for the help, but I don't really understand this lol.

Ha! I'm not good with simple scripts…
blakelarson19
Scratcher
24 posts

Pick number a or number b?

piggiety wrote:

blakelarson19 wrote:

piggiety wrote:

Oh! I get it. This might work:

whenclickedsetrandomizertopickrandom1to10addrandomizertolistmoverandomizerstepssetrandomizertopickrandom1to10repeatuntilnotrandomizer=item1oflist+1orrandomizer=item1oflist-1ifrandomizer=item1oflist+1thensetrandomizertopickrandom1to10ifrandomizer=item1oflist-1thensetrandomizertopickrandom1to10moverandomizersteps

This is super complicated, but I hope it helps! I didn't know what the numbers were used for, so I just put in a bunch of move … steps. You can get rid of those if you want.

Thank you for the help, but I don't really understand this lol.

Ha! I'm not good with simple scripts…

Should I share my project would that help?
georgeskey
Scratcher
100+ posts

Pick number a or number b?

You could simply do:

whenclickedsetnumber helptopickrandom1to2ifnumberhelp=1thensetnumbertoinsertnumberhereelsesetnumbertoinsertothernumberhere
Or, to make it a little more reusable and easy,
definetwonumbersfirstnumbersecondnumbersetnumber helptopickrandom1to2ifnumberhelp=1thensetnumbertofirstnumberelsesetnumbertosecondnumber
blakelarson19
Scratcher
24 posts

Pick number a or number b?

georgeskey wrote:

You could simply do:

whenclickedsetnumber helptopickrandom1to2ifnumberhelp=1thensetnumbertoinsertnumberhereelsesetnumbertoinsertothernumberhere
Or, to make it a little more reusable and easy,
definetwonumbersfirstnumbersecondnumbersetnumber helptopickrandom1to2ifnumberhelp=1thensetnumbertofirstnumberelsesetnumbertosecondnumber

Thank you, will the computer be able to process this quickly enough? This makes sense though and I'm trying it right now.
georgeskey
Scratcher
100+ posts

Pick number a or number b?

georgeskey wrote:

You could simply do:

whenclickedsetnumber helptopickrandom1to2ifnumberhelp=1thensetnumbertoinsertnumberhereelsesetnumbertoinsertothernumberhere
Or, to make it a little more reusable and easy,
definetwonumbersfirstnumbersecondnumbersetnumber helptopickrandom1to2ifnumberhelp=1thensetnumbertofirstnumberelsesetnumbertosecondnumber
And if you mean randomly pick two numbers, you can just do:
whenclickedsetfirst numbertopickrandom-100to100setsecond numbertopickrandom-100to100repeatuntilnotabsoffirstnumber-secondnumber=1setsecond numbertopickrandom-100to100
zp100
Scratcher
100+ posts

Pick number a or number b?

A really easy way would be:
pickrandom1to2*2+1
This will give either 3 or 5. Change the 1 at the end to a 3 to make it pick 5 or 7.

Last edited by zp100 (May 19, 2016 00:12:14)

deck26
Scratcher
1000+ posts

Pick number a or number b?

zp100 wrote:

A really easy way would be:
pickrandom1to2*2+1
This will give either 3 or 5. Change the 1 at the end to a 3 to make it pick 5 or 7.
Or change the second 2 to 3 and leave the 1 at the end alone. If you just want to pick between two numbers there's always a similar method but if doing different numbers throughout your project a custom block will be clearest.
zp100
Scratcher
100+ posts

Pick number a or number b?

deck26 wrote:

zp100 wrote:

A really easy way would be:
pickrandom1to2*2+1
This will give either 3 or 5. Change the 1 at the end to a 3 to make it pick 5 or 7.
Or change the second 2 to 3 and leave the 1 at the end alone. If you just want to pick between two numbers there's always a similar method but if doing different numbers throughout your project a custom block will be clearest.
Changing the second 2 to a 3 would make it 3 or 6. And, you could make this with a custom block. It would look like this:
definesetvartonum1ornum2setvartopickrandom1to2*num2-num1+num1-num2-num1

Last edited by zp100 (May 20, 2016 00:01:08)

deck26
Scratcher
1000+ posts

Pick number a or number b?

zp100 wrote:

deck26 wrote:

zp100 wrote:

A really easy way would be:
pickrandom1to2*2+1
This will give either 3 or 5. Change the 1 at the end to a 3 to make it pick 5 or 7.
Or change the second 2 to 3 and leave the 1 at the end alone. If you just want to pick between two numbers there's always a similar method but if doing different numbers throughout your project a custom block will be clearest.
Changing the second 2 to a 3 would make it 3 or 6. And, you could make this with a custom block. It would look like this:
definesetvartonum1ornum2setvartopickrandom1to2*num2-num1+num1-num2-num1
My mistake, must have been distracted! Random 2 to 3 times 2 plus 1 gives 5 or 7. Apologies for any confusion.
deck26
Scratcher
1000+ posts

Pick number a or number b?

If making a custom block though much easier to just use random 1 to 2 to choose first or second.

Last edited by deck26 (May 20, 2016 07:07:35)

drmcw
Scratcher
1000+ posts

Pick number a or number b?

or
add3torandom numbers add5torandom numbers setrandom picktoitemrandomofrandom numbers
zp100
Scratcher
100+ posts

Pick number a or number b?

drmcw wrote:

or
add3torandom numbers add5torandom numbers setrandom picktoitemrandomofrandom numbers
Yes, that would probably be the simplest, but my idea doesn't require a list.
blakelarson19
Scratcher
24 posts

Pick number a or number b?

Thanks guys for the advice, but earlier in the thread I found a solution,
iftouchingD1?thensetNumer Helpto(pick random (1) to (2)) ifNumberHelp=1thensetWolf Directionto2 ifNumberHelp=2thensetWolf Directionto4
jokebookservice1
Scratcher
1000+ posts

Pick number a or number b?

blakelarson19 wrote:

Thanks guys for the advice, but earlier in the thread I found a solution,
iftouchingD1?thensetNumer Helpto(pick random (1) to (2)) ifNumberHelp=1thensetWolf Directionto2 ifNumberHelp=2thensetWolf Directionto4
Don't nest the ifs, because if Number Help = 1, it can't become 2 before the next nested if statement
zp100
Scratcher
100+ posts

Pick number a or number b?

blakelarson19 wrote:

Thanks guys for the advice, but earlier in the thread I found a solution,
iftouchingD1?thensetNumer Helpto(pick random (1) to (2)) ifNumberHelp=1thensetWolf Directionto2 ifNumberHelp=2thensetWolf Directionto4
It would be much easier to just do
iftouchingD1?thensetNumer Helptopickrandom1to2*2
It would give the exact same result, but with fewer blocks and less space.

Powered by DjangoBB