Script for Random Number
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 9
- Joined: Sun Jun 30, 2013 8:23 pm
Script for Random Number
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.
-
- VIP Livecode Opensource Backer
- Posts: 153
- Joined: Thu Jun 29, 2006 4:16 pm
Re: Script for Random Number
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
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
-
- Posts: 9
- Joined: Sun Jun 30, 2013 8:23 pm
Re: Script for Random Number
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!!
-
- VIP Livecode Opensource Backer
- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
- Location: Palo Alto
Re: Script for Random Number
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
Simon
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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
-
- Livecode Opensource Backer
- Posts: 1336
- Joined: Sun Jul 12, 2009 10:53 am
- Location: Bordeaux, France
Re: Script for Random Number
Gordon...
Does this help ?
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
-
- VIP Livecode Opensource Backer
- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
- Location: Palo Alto
Re: Script for Random Number
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
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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
-
- Posts: 9
- Joined: Sun Jun 30, 2013 8:23 pm
Re: Script for Random Number
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.
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.
Last edited by gordonshim on Mon Aug 12, 2013 6:35 pm, edited 1 time in total.
Re: Script for Random Number
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
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
-
- Posts: 9
- Joined: Sun Jun 30, 2013 8:23 pm
Re: Script for Random Number
Hi Klaus,
So where did you move it to?...tanks!
So where did you move it to?...tanks!
Re: Script for Random Number
Moved it to here!
Come on, Gordon, check the top of this page and you will see...
Come on, Gordon, check the top of this page and you will see...
-
- VIP Livecode Opensource Backer
- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
- Location: Palo Alto
Re: Script for Random Number
Well I feel slighted.
Last time I lift up my skirt for Gordon.
Simon
Last time I lift up my skirt for Gordon.
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
-
- Livecode Opensource Backer
- Posts: 1336
- Joined: Sun Jul 12, 2009 10:53 am
- Location: Bordeaux, France
Re: Script for Random Number
Gordon...
I think this will do what you want
I think this will do what you want
- Attachments
-
- multipliers.livecode.zip
- (1.21 KiB) Downloaded 288 times
-
- Posts: 9
- Joined: Sun Jun 30, 2013 8:23 pm
Re: Script for Random Number
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!!
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: Script for Random Number
..........
Last edited by [-hh] on Wed Aug 13, 2014 12:17 pm, edited 1 time in total.
shiftLock happens
-
- Posts: 9
- Joined: Sun Jun 30, 2013 8:23 pm
Re: Script for Random Number
Yes you are correct. Random "sort" is accurate. I get it. Thank you.