Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Pick random:
- FUTSync
-
Scratcher
100+ posts
Pick random:
Im trying to basically choose a number between 1 & 10, But not 4 or 5.
Tried
But and wont let them join.
I may be being quite stupid here. Im a bit rusty on my scratch knowledge recently
Tried
<<pick random (1) to (3)> and (pick random (5) to (10))>
But and wont let them join.
I may be being quite stupid here. Im a bit rusty on my scratch knowledge recently

- deck26
-
Scratcher
1000+ posts
Pick random:
Various options but not possible in a single block.
set [myvar v] to (pick random (1) to (8))
if <(myvar) > [3]> then
change [myvar v] by [2]
end
- asivi
-
Scratcher
1000+ posts
Pick random:
set [digits v] to [123678]
(letter (pick random (1) to (6)) of (digits))//you don't need the variable at all
Last edited by asivi (Oct. 3, 2017 12:23:08)
- gtoal
-
Scratcher
1000+ posts
Pick random:
It's possible to make a function with no loops and no lookup tables that maps 1..8 to 1..3, 6..10 omitting 4,5
Here's the code: https://scratch.mit.edu/projects/177945410/#editor
Sorry, it was too complex to recode as scratchblocks and I think the scratchblocks generator is offline.
First I derived a function to create a 1 unit gap, and then used the output from that in another copy that created a second 1-unit gap.
Somewhat hackily derived by trial and error in this case, though it should be possible to rigorously derive these functions in the general case.
Here's the code: https://scratch.mit.edu/projects/177945410/#editor
Sorry, it was too complex to recode as scratchblocks and I think the scratchblocks generator is offline.
First I derived a function to create a 1 unit gap, and then used the output from that in another copy that created a second 1-unit gap.
Somewhat hackily derived by trial and error in this case, though it should be possible to rigorously derive these functions in the general case.
Last edited by gtoal (Oct. 4, 2017 04:52:40)
- deck26
-
Scratcher
1000+ posts
Pick random:
It's possible to make a function with no loops and no lookup tables that maps 1..8 to 1..3, 6..10 omitting 4,5Err, you seem to have omitted 5 and 6 rather than 4 and 5.
Here's the code: https://scratch.mit.edu/projects/177945410/#editor
Sorry, it was too complex to recode as scratchblocks and I think the scratchblocks generator is offline.
First I derived a function to create a 1 unit gap, and then used the output from that in another copy that created a second 1-unit gap.
Somewhat hackily derived by trial and error in this case, though it should be possible to rigorously derive these functions in the general case.
This is the sort of thing you come across 6 months later and wonder what it does and why you did it that way! Having had programs which I've had to maintain and modify over 25 years in some cases I'd go for something I can immediately understand every time.
But obviously I shouldn't have said it wasn't possible in a single block, that was just asking to be proved wrong.
- gtoal
-
Scratcher
1000+ posts
Pick random:
Err, you seem to have omitted 5 and 6 rather than 4 and 5.
This is the sort of thing you come across 6 months later and wonder what it does and why you did it that way! Having had programs which I've had to maintain and modify over 25 years in some cases I'd go for something I can immediately understand every time.
But obviously I shouldn't have said it wasn't possible in a single block, that was just asking to be proved wrong.
Good catch! Adjust -1 at the end of the expression to -2, and move the ‘pick random’ range up by one from 2:9 to 3:10 … solved :-)
You're right of course, I would never use a function like this in a million years … unless of course I were writing some SIMD superscalar code for a GPU and could not afford to use conditionals which break the pipeline. Then you might have to use tricks like this.
But really I just wanted to see if it could be done :-)
G
- gtoal
-
Scratcher
1000+ posts
Pick random:
You used 1 to 6 in your example because this method doesn't cope with “10”? :-)set [digits v] to [123678]
(letter (pick random (1) to (6)) of (digits))//you don't need the variable at all
- asivi
-
Scratcher
1000+ posts
Pick random:
Yeah, otherwise i would use a lookup table stored in a list. 

- RealUnspeakable_1
-
Scratcher
1 post
Pick random:
Hey, come check out my new game I made a few days ago it also uses the “random” function
https://scratch.mit.edu/projects/330292172
(copy this link into google)
https://scratch.mit.edu/projects/330292172
(copy this link into google)

- oscarfinley
-
Scratcher
100+ posts
Pick random:
First of all, this belongs in the ‘show and tell’ forum
secondly, this forum was about a specific randomiser which omits certain numbers, which your project does not include
secondly, this forum was about a specific randomiser which omits certain numbers, which your project does not include
- deck26
-
Scratcher
1000+ posts
Pick random:
@speedycatfish2
and i will no f4f youPlease don't spam or necropost. You risk being reported.
- BlueBalloon11
-
Scratcher
4 posts
Pick random:
Im trying to basically choose a number between 1 & 10, But not 4 or 5.
Tried<<pick random (1) to (3)> and (pick random (5) to (10))>
But and wont let them join.
I may be being quite stupid here. Im a bit rusty on my scratch knowledge recently
you have to pur the <<pick random (1) to (3)> or (pick random (5) to (10))>
it has to be ‘or’ not ‘and’
loL you are being stupid too, no critisism though
Last edited by BlueBalloon11 (April 4, 2022 12:49:35)
- BlueBalloon11
-
Scratcher
4 posts
Pick random:
First of all, this belongs in the ‘show and tell’ forumOSCARFINLEY UR TRASH
secondly, this forum was about a specific randomiser which omits certain numbers, which your project does not include
- historical_supa
-
Scratcher
1000+ posts
Pick random:
Im trying to basically choose a number between 1 & 10, But not 4 or 5.
Tried<<pick random (1) to (3)> and (pick random (5) to (10))>
But and wont let them join.
I may be being quite stupid here. Im a bit rusty on my scratch knowledge recently
you have to pur the <<pick random (1) to (3)> or (pick random (5) to (10))>
it has to be ‘or’ not ‘and’
loL you are being stupid too, no critisism though
Please don't necropost, which means an unconstructive post on a very very old topic.First of all, this belongs in the ‘show and tell’ forumOSCARFINLEY UR TRASH
secondly, this forum was about a specific randomiser which omits certain numbers, which your project does not include
- Discussion Forums
- » Help with Scripts
-
» Pick random:

