Page 1 of 1
Script for Random Number
Posted: Sun Aug 11, 2013 7:56 pm
by gordonshim
Not being a "real" programmer, I'm a bit intimated by code written in this forum and others that I've searched for online. I am looking for a simple script that involves picking a number in an array of just 9 numbers (but no more than 100) only ONCE and continue picking until all numbers 9 numbers (or all 100) are picked. I sure someone out there has this "canned." Thank you in advance.
Re: Script for Random Number
Posted: Sun Aug 11, 2013 8:47 pm
by Randy Hengst
I'm not totally sure what you're looking for… put this in a button and see if it's at all along the lines you were thinking.
on mouseUp
local tYourNumberList
put empty into tYourNumberList
repeat with x = 1 to 100 -- or to whatever number you want
put x & "," after tYourNumberList
end repeat
delete char -1 tYourNumberList -- removes the trailing comma-- which you need to do before a sort
sort items of tYourNumberList by random(10000)
put tYourNumberList -- just to see the contents
end mouseUp
Re: Script for Random Number
Posted: Mon Aug 12, 2013 4:43 am
by gordonshim
Randy...Thank you for this script. I placed it into a button of a stack I am creating for my class. Your script works well, but not for what I had in mind. Let me clarify myself. I want to randomly select multipliers 1 to 9 before I use it to multiply it with other values. Once I use a multiplier, I need it to be removed so that it won't be used again. Succeeding random multipliers should also be removed until all 9 values (multipliers) are used. Yes, I want my students to practice their times tables for multiplier values 1 to 9 only (forget about the 10, 11, and 12 that I had to memorize when I was in the 4th grade!!
Re: Script for Random Number
Posted: Mon Aug 12, 2013 5:28 am
by Simon
Hi gordonshim,
Not sure if I got this right either but:
New stack with 1 fld and 1 button on it:
enter 1,2,3,4,5,6,7,8,9 into the field and
Code: Select all
on mouseUp
get random(number of items of fld 1)
-- do something with the it var.
delete item it of fld 1
if fld 1 = "" then disable me
end mouseUp
Simon
Re: Script for Random Number
Posted: Mon Aug 12, 2013 5:29 am
by Dixie
Gordon...
Does this help ?
Code: Select all
local theMultipliers, theNumber
on resetTheMultipliers
repeat with count = 1 to 9
put count & comma after theMultipliers
end repeat
delete the last char of theMultipliers
end resetTheMultipliers
on mouseUp
if theMultipliers is empty then
resetTheMultipliers
end if
/* have theNumber as a local variable, so that you can use it later how you wish */
put random(the number of items of theMultipliers) into theNumber
/* get rid of the last chosen multiplier from the list of multipliers
so that you don't use it again*/
delete item theNumber of theMultipliers
/* so you can see the list of multipliers that is left */
put theMultipliers
end mouseUp
Re: Script for Random Number
Posted: Mon Aug 12, 2013 5:42 am
by Simon
Gordon,
Whats really good is if you see Dixie's script and mine are the same.
Dixie's is better because he has more 'filthy lucre'
Simon
Re: Script for Random Number
Posted: Mon Aug 12, 2013 5:46 am
by gordonshim
Hello Dixie.....WOW!!..Works great!! I can't thank you enough. Should be able to use this script in other areas of future random number selection.
Hello again...Yes it does work, but I can't seem to capture that number that is deleted from what is left. I created this fld that I named "theLeftOverX" to see what is left. It does show what's left after pressing this button the first time. I need to capture all deleted multiplier when this button is activated so I created this fld that I named "theActiveX" to see. The first deleted multiplier does show up into this fld. However, subsequent deleted multipliers still shows up into my "theLeftOverX" Please advise.
Re: Script for Random Number
Posted: Mon Aug 12, 2013 1:14 pm
by Klaus
HI all,
will move this thread to the correct forum, since this is NOT a feature request in the actual meaning of the term in this context
Re: Script for Random Number
Posted: Mon Aug 12, 2013 6:25 pm
by gordonshim
Hi Klaus,
So where did you move it to?...tanks!
Re: Script for Random Number
Posted: Mon Aug 12, 2013 6:38 pm
by Klaus
Moved it to here!
Come on, Gordon, check the top of this page and you will see...
Re: Script for Random Number
Posted: Mon Aug 12, 2013 6:47 pm
by Simon
Well I feel slighted.
Last time I lift up my skirt for Gordon.
Simon
Re: Script for Random Number
Posted: Mon Aug 12, 2013 6:57 pm
by Dixie
Gordon...
I think this will do what you want
Re: Script for Random Number
Posted: Mon Aug 12, 2013 7:50 pm
by gordonshim
U DA BEST!! .... must do this for a living!! I'm now able to capture the last value in the used fld and I'm now on my way to completing this stack before school starts. Many thanks for hanging with me. I really do appreciate that. My apologies to you Klaus and Simon for being such a rookie at this. I am definitely learning thanks to all that contribute to this forum. Maybe someday, I will return the favor. Now...back to my day job!!
Re: Script for Random Number
Posted: Sun Sep 08, 2013 1:10 am
by [-hh]
..........
Re: Script for Random Number
Posted: Sun Sep 08, 2013 3:42 pm
by gordonshim
Yes you are correct. Random "sort" is accurate. I get it. Thank you.