Discuss Scratch
- varadyjc
- Scratcher
56 posts
How the "Pick Random" Block Works
My question is quite simple. How does the
Any answer is appreciated.
(pick random (1) to (10))block work? How does it decide what number to choose?
Any answer is appreciated.
Last edited by varadyjc (Sept. 4, 2016 16:18:18)
- varadyjc
- Scratcher
56 posts
How the "Pick Random" Block Works
I think it might have to do applying several calculations to the current time to produce a near-random number.
Last edited by varadyjc (Sept. 4, 2016 16:19:29)
- jokebookservice1
- Scratcher
1000+ posts
How the "Pick Random" Block Works
near-random number.Yes, it has to be predetermined, it just looks random. These random numbers are called pseudo-random numbers. I think it might have to do applying several calculations to the current time to produce a
Scratch uses Math.random so this might hep?
- -Io-
- Scratcher
1000+ posts
How the "Pick Random" Block Works
near-random number.As far as I know, that's it I think it might have to do applying several calculations to the current time to produce a
Scratch uses AS3's Math.random. It's a pseudo-random generator and thus it needs a seed which is most of the times just the current time.
EDIT: ninja'd :p
Last edited by -Io- (Sept. 4, 2016 17:08:02)
- varadyjc
- Scratcher
56 posts
How the "Pick Random" Block Works
Thank you!near-random number.As far as I know, that's it I think it might have to do applying several calculations to the current time to produce a
Scratch uses AS3's Math.random. It's a pseudo-random generator and thus it needs a seed which is most of the times just the current time.
EDIT: ninja'd :p
- varadyjc
- Scratcher
56 posts
How the "Pick Random" Block Works
Thank you! That's helpful!near-random number.Yes, it has to be predetermined, it just looks random. These random numbers are called pseudo-random numbers. I think it might have to do applying several calculations to the current time to produce a
Scratch uses Math.random so this might hep?
- TheLogFather
- Scratcher
1000+ posts
How the "Pick Random" Block Works
There are some oddities about it that you might want to be aware of…
https://scratch.mit.edu/projects/96080245/
In particular, note that it has a resolution of 1 in 2^31. That means if you “pick random (0.0) to (1.0)”, which picks a random real number from zero to one, and then multiply it by 2^31, it will always end up with an integer value.
Also, note that Scratch's “pick random” block is meant to give an integer result if both entries are integers. But if either is written as a real number (e.g. “1.0” or “0.0”, as above) then it will give a real value (with the 1 in 2^31 resolution).
However, there's a glitch in the way values are saved which means that entries like “1.0” and “0.0” (i.e. something which is written as a real value, but is equal to an integer) end being turned into integer values when the project is next loaded. (So “0.0” becomes “0” and “1.0” becomes “1”). This means “pick random 0.0 to 1.0” will give real values before you save the project, and get transformed into “pick random 0 to 1” on reloading, so it then only gives either zero or one…
Hope those are helpful!
https://scratch.mit.edu/projects/96080245/
In particular, note that it has a resolution of 1 in 2^31. That means if you “pick random (0.0) to (1.0)”, which picks a random real number from zero to one, and then multiply it by 2^31, it will always end up with an integer value.
Also, note that Scratch's “pick random” block is meant to give an integer result if both entries are integers. But if either is written as a real number (e.g. “1.0” or “0.0”, as above) then it will give a real value (with the 1 in 2^31 resolution).
However, there's a glitch in the way values are saved which means that entries like “1.0” and “0.0” (i.e. something which is written as a real value, but is equal to an integer) end being turned into integer values when the project is next loaded. (So “0.0” becomes “0” and “1.0” becomes “1”). This means “pick random 0.0 to 1.0” will give real values before you save the project, and get transformed into “pick random 0 to 1” on reloading, so it then only gives either zero or one…
Hope those are helpful!
Last edited by TheLogFather (Sept. 4, 2016 21:27:22)
Siggy the Kumquat slayer:
Main account: DadOfMrLog –– Frameworks for basic pen-rendered 3D in scratch (see studio). Examples:
- - - - 3D Text - - - - - - Simple shapes - - - Controllable structures - - - On the ground - - - - - - In space - - - -
- - - - 3D Text - - - - - - Simple shapes - - - Controllable structures - - - On the ground - - - - - - In space - - - -
- IcyCoder
- Scratcher
1000+ posts
How the "Pick Random" Block Works
How can you make a pick random block alternitive
Because JS is the future (echos) future future futur futu fut fu f
- Jonathan50
- Scratcher
1000+ posts
How the "Pick Random" Block Works
Use one of How can you make a pick random block alternitivethese algorithms.
Not yet a Knight of the Mu Calculus.
- scratchisthebest
- Scratcher
1000+ posts
How the "Pick Random" Block Works
before you save the project, and get transformed into “pick random 0 to 1” on reloading, so it then only gives either zero or one…Are there ways around this bug? However, there's a glitch in the way values are saved which means that entries like “1.0” and “0.0” (i.e. something which is written as a real value, but is equal to an integer) end being turned into integer values when the project is next loaded. (So “0.0” becomes “0” and “1.0” becomes “1”). This means “pick random 0.0 to 1.0” will give real values
One way I can think of is “pick random 0 to 1.000000000001”, but I'm sure there's a smarter solution right?
I am a Lava Expert
- IcyCoder
- Scratcher
1000+ posts
How the "Pick Random" Block Works
Question: in this situation is there really a 50% chance of it equaling one?
(pick random (1) to (2))
Because JS is the future (echos) future future futur futu fut fu f
- TheLogFather
- Scratcher
1000+ posts
How the "Pick Random" Block Works
Are there ways around this bug?
One way I can think of is “pick random 0 to 1.000000000001”, but I'm sure there's a smarter solution right?
I replied:I just realised that, on my ‘pick random investigations’ project, @asivi pointed me to a project that puts a single dot into the first slot. Scratch translates that into a zero, but with two useful properties:
That's pretty much what I've done with it…
Unfortunately, you can't even use tricks such as “join” to turn it into a string (e.g. "join [1.] [0]“, or something), ‘cos Scratch converts it into a numerical value (since it knows that’s the type of the input), so it then ends up as just the value 1, which it then considers to be an integer.
For ”0.0“, I do something like ”1e-50".
1) It contains a decimal point, so Scratch treats it as a real number, meaning “pick random” will return a real number;
2) Scratch does *save* it as a dot, so it gets reloaded as a dot and will therefore continue to work across reloads.
That means you can easily create a “pick random from (first) to (last)” that works for real numbers:
( (pick random (.) to ((last)-(first))) + (first) ) // The dot gets translated as "0.0" but is kept across reloads.
Last edited by TheLogFather (Sept. 5, 2016 14:56:41)
Siggy the Kumquat slayer:
Main account: DadOfMrLog –– Frameworks for basic pen-rendered 3D in scratch (see studio). Examples:
- - - - 3D Text - - - - - - Simple shapes - - - Controllable structures - - - On the ground - - - - - - In space - - - -
- - - - 3D Text - - - - - - Simple shapes - - - Controllable structures - - - On the ground - - - - - - In space - - - -
- Dylan5797
- Scratcher
1000+ posts
How the "Pick Random" Block Works
Implement a pseudorandom algorithm in scratch (which would be huge and a waste of time to make) How can you make a pick random block alternitive
- varadyjc
- Scratcher
56 posts
How the "Pick Random" Block Works
Thanks to everyone, you all answered my questions really well!
Relevant links:
https://en.wikipedia.org/wiki/Pseudorandom_number_generator
https://scratch.mit.edu/projects/96080245/
http://stackoverflow.com/questions/20109006/how-does-math-random-work-in-javascript
https://scratch.mit.edu/projects/69020062/
Relevant links:
https://en.wikipedia.org/wiki/Pseudorandom_number_generator
https://scratch.mit.edu/projects/96080245/
http://stackoverflow.com/questions/20109006/how-does-math-random-work-in-javascript
https://scratch.mit.edu/projects/69020062/
- TheLogFather
- Scratcher
1000+ posts
How the "Pick Random" Block Works
Woah…! Did I really just EDIT my post above rather than actually quote it to post a new reply…
…and now I can't remember all that it originally said, so all that's left is the bit in there that I quoted from it…
…and now I can't remember all that it originally said, so all that's left is the bit in there that I quoted from it…
Last edited by TheLogFather (Sept. 5, 2016 15:01:58)
Siggy the Kumquat slayer:
Main account: DadOfMrLog –– Frameworks for basic pen-rendered 3D in scratch (see studio). Examples:
- - - - 3D Text - - - - - - Simple shapes - - - Controllable structures - - - On the ground - - - - - - In space - - - -
- - - - 3D Text - - - - - - Simple shapes - - - Controllable structures - - - On the ground - - - - - - In space - - - -
- wizzwizz7
- Scratcher
500+ posts
How the "Pick Random" Block Works
before you save the project, and get transformed into “pick random 0 to 1” on reloading, so it then only gives either zero or one…Are there ways around this bug? However, there's a glitch in the way values are saved which means that entries like “1.0” and “0.0” (i.e. something which is written as a real value, but is equal to an integer) end being turned into integer values when the project is next loaded. (So “0.0” becomes “0” and “1.0” becomes “1”). This means “pick random 0.0 to 1.0” will give real values
One way I can think of is “pick random 0 to 1.000000000001”, but I'm sure there's a smarter solution right?
pick random (0) to (join[1][.0])
- CodeLegend
- Scratcher
500+ posts
How the "Pick Random" Block Works
before you save the project, and get transformed into “pick random 0 to 1” on reloading, so it then only gives either zero or one…Obfuscated remix detection, anyone? However, there's a glitch in the way values are saved which means that entries like “1.0” and “0.0” (i.e. something which is written as a real value, but is equal to an integer) end being turned into integer values when the project is next loaded. (So “0.0” becomes “0” and “1.0” becomes “1”). This means “pick random 0.0 to 1.0” will give real values
- PullJosh
- Scratcher
1000+ posts
How the "Pick Random" Block Works
Oooh, that's clever. I'm not a big fan of actually preventing remixes on projects (remixing is a fantastic way to learn), but it would be fun to play around with just to see if it's possible. Obfuscated remix detection, anyone?
- CodeLegend
- Scratcher
500+ posts
How the "Pick Random" Block Works
Same here. I wonder if this would work when someone remixes without making any edits?Oooh, that's clever. I'm not a big fan of actually preventing remixes on projects (remixing is a fantastic way to learn), but it would be fun to play around with just to see if it's possible. Obfuscated remix detection, anyone?
- IcyCoder
- Scratcher
1000+ posts
How the "Pick Random" Block Works
hmm really cool idea.Same here. I wonder if this would work when someone remixes without making any edits?Oooh, that's clever. I'm not a big fan of actually preventing remixes on projects (remixing is a fantastic way to learn), but it would be fun to play around with just to see if it's possible. Obfuscated remix detection, anyone?
Because JS is the future (echos) future future futur futu fut fu f