Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

RANDOM's & PICK's args

 [1/8] from: ddalley::idirect::com at: 19-Jan-2002 19:03


Hi, REBOLs: I am trying to PICK a set (say 3-9) of random, non-duplicated strings out of a block of 50. The strings are to be presented as a row of BUTTONs. BUTTON needs a string... How do we use >both< a RANDOM range and a seed, at the same time? The docs don't show how and all efforts, so far, have failed. Also, PICK always complains that the index arg is of the wrong type, when I try to combine the two procedures. I used a word & a number, but it didn't work with either. The following are some ideas I used, but getting a random string has never worked, so it has become messy: balls: [ "String 1" "String 2" "String 3 " ... "String 50" ] b-seed: RANDOM 50 pick-string FUNC [ "Picks a random string from balls." balls b-seed][ PICK balls (PROBE b-seed) ; yes, more work is needed here ] Tried to display each string with something like BUTTON pick-string MAROON 50x50 FONT-SIZE 32 but now the string does not display in the button. I was thinking that removing each string from balls, when picked, would ensure that there were no duplicates, but I haven't tried yet. CLEAR, CHANGE & REMOVE are like using a chainsaw, therefore I presume REPLACE is needed to delete just one element from a series/block. How can REPLACE be used to not leave a blank string in the block, so that it can't be picked? This would also affect RANDOM's range the way I am using it. Any help/ideas will be appreciated. Donald Dalley

 [2/8] from: rebol:optushome:au at: 20-Jan-2002 10:39


Hi Donald, Does this help? balls: [ "B1" "B2" "B3" "B4" "B5" "B6" "B7" "B8" "B9" "B10" "B11" "B12" "B13" "B14" "B15" "B16" "B17" "B18" "B19" "B20" "B21" "B22" "B23" "B24" "B25" "B26" "B27" "B28" "B29" "B30" ] pick-balls: func [count seed][ random/seed seed copy/part random copy balls count ] pick-balls 3 1 == ["B15" "B2" "B10"]

 [3/8] from: tomc:darkwing:uoregon at: 19-Jan-2002 16:54


If I am understanding you.. you should only need to seed RANDOM once, anywhere before you use it, then yes you could could mess with your source array to avoid duplication ,and you could check for dups each time you added a string... but you also might get lucky... and if not your target array is smaller so it's better to tweak that rebol[] random/seed now ;... set-size: 6 set: make block! set-size balls: copy [] for i 1 50 1 [append/only balls rejoin["String " i]] loop set-size[append/only set pick balls random 50] set: unique set while[(length? set) < set-size][ append/only set pick balls random 50 set: unique set ] On Sat, 19 Jan 2002, Donald Dalley wrote:

 [4/8] from: rebol665:ifrance at: 20-Jan-2002 10:50


Hi Donald With Rebol, you can use random directly on a block of string to get the same block randomized. colors: ["red" "green" "yellow" "blue" "white"] while [not tail? colors] [ colors: random colors print first colors remove colors ] ;blue ;yellow ;green ;red ;white HTH Patrick

 [5/8] from: chalz:earthlink at: 21-Jan-2002 0:50


I think I'm late on this list, but herein lies a question I need answered, too.
> I was thinking that removing each string from balls, when picked, would > ensure that there were no duplicates, but I haven't tried yet. CLEAR,
CHANGE
> & REMOVE are like using a chainsaw, therefore I presume REPLACE is needed
to
> delete just one element from a series/block. How can REPLACE be used to
not
> leave a blank string in the block, so that it can't be picked? This would > also affect RANDOM's range the way I am using it.
My problem, usually, has been that when using a for loop on a series which gets altered, the loop fails to access the altered series/block, but continues to use the original. How do I go around this? (Ie, if I have [a b c d] and I run a for loop through it, when the loop reaches c, I want to append [e f g] to the block, and continue running the loop through e f g...) Does this make sense? Thanks everyone. --Charles

 [6/8] from: ryanc:iesco-dms at: 21-Jan-2002 9:49


The 'forall loop is perfect for such instances. --Ryan Charles wrote:
> I think I'm late on this list, but herein lies a question I need > answered, too.
<<quoted lines omitted: 28>>
> [rebol-request--rebol--com] with "unsubscribe" in the > subject, without the quotes.
-- Ryan Cole Programmer Analyst www.iesco-dms.com 707-468-5400 The contradiction so puzzling to the ordinary way of thinking comes from the fact that we have to use language to communicate our inner experience which in its very nature transcends lingistics. -D.T. Suzuki

 [7/8] from: ddalley:idirect at: 21-Jan-2002 14:41


Thanks, Pat! I hadn't seen this usage before. It is also a much simpler basis than what I was working on. Donald Dalley

 [8/8] from: ddalley:idirect at: 21-Jan-2002 23:15


Hi, REBOLs: OK, I got the basic random idea working as a simple example program. I'll put it up on my REB site, once I make it presentable. Thanks for everyone's help. Donald Dalley

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted