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

#1 2013-02-06 06:39:07

perceivedcompetence
New Scratcher
Registered: 2013-02-02
Posts: 1

How to record random generated values, in order, for later use. :)

Hello beautiful people,

i wanted to ask a question as i seem to be in a runt with it. I want to record the random generated values, i imagine it should have something to do with broadcast, but i run into a problem that the second random variable is generated, the first one gets rewritten, and i want to record them all, so later i could differentiate the order they were generated, from first to last.

Any help?

Thanks

Offline

 

#2 2013-02-06 14:15:44

dechan
Scratcher
Registered: 2012-12-20
Posts: 69

Re: How to record random generated values, in order, for later use. :)

This sounds like a great list-study project.
You do not need to broadcast anything.
I'll try to scratchblocks the algorithm for you:
list name: random_numbers

when gf clicked
delete [all v] of [random_numbers v]
repeat [10]
  add <pick random [1] to [10]> to [random_numbers v]
end
Then to recall one of those numbers you can do the following
set [foo v] to (item <pick random [1] to (length of [random_numbers v])> of [random_numbers v])
Ugh! Scratchblocks can be painful to get right.  smile
Ran out of time to make a comment earlier in the day--scratchblocks gobbled up my time.

I wanted to cover the basics of populating the list, and then leave the sorting up to the wiki.

Last edited by dechan (2013-02-06 22:27:03)

Offline

 

#3 2013-02-06 15:24:34

Firedrake969
Scratcher
Registered: 2011-11-24
Posts: 1000+

Re: How to record random generated values, in order, for later use. :)

I think he means sorting a list of random numbers.

I would probably do a merge sort, but those would be hard.
A simple bubble sort would first
-add all random numbers to list
-do a repeat loop for the length of the list

will think of more later


Click the sign.
https://s3.amazonaws.com/eterna/eterna2/logo2.png

Offline

 

Board footer