Shop OBEX P1 Docs P2 Docs Learn Events
Tricky Random Question — Parallax Forums

Tricky Random Question

ArchiverArchiver Posts: 46,084
edited 2002-06-13 23:05 in General Discussion
Hi everyone,

I am working on a project and I have some random problem that might be easy
for you bit-wizards but seems too tricky for me:

I want to play 90 different files from a quadravox-soundchip. (it is a poem
spoken by a friend of mine). The aim is to play all 90 sounds in a random
order and next time in another order.
Always all 90 sounds shall be used. Aditionally no order should appear
twice, so that after a (very) long time every possible poem made out of the
90 words should have been played once.

How would I program this?

Thanx a lot, Uli


[noparse][[/noparse]Non-text portions of this message have been removed]

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2002-06-12 13:57
    Hi Uli,

    This is the "shuffled card deck" problem. I'd use a Stamp with scratch
    pad memory like the BS2SX or BS2P. The reason is you need a bit to
    represent the 90 "cards". That will take nearly 12 bytes. The process
    is:

    done:
    count=0
    gosub set_all_bits_to_one
    wait:
    gosub wait_for_user_input

    top:
    if count=90 then done
    gosub generate_random_number
    if bitarray[noparse][[/noparse]number]=0 then top ' already did that one
    count=count+1
    bitarray[noparse][[/noparse]number]=0
    gosub do_sound_by_number
    goto wait


    Something like that? Of course, if the random number gets stuck so do
    you. Another strategy would be to say:
    gosub generate_random_number ' same as code above
    loop:
    if bitarray[noparse][[/noparse]number]=1 then exitloop
    number=number+1
    if number<90 then loop
    number=0
    goto loop
    exitloop:
    count=count+1 ' same as code above
    .
    .
    .

    This replaces the if bitarray test in the first snip.

    Al Williams
    AWC
    * 8 channels of PWM
    http://www.al-williams.com/awce/pak5.htm


    >
    Original Message
    > From: ulibasic [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=G4UhN4aA70JTM4GmAWB5m9gcpQuOJDX6AcOKm1_zxZij_rb1BCbsXF5ygvsAxPGaNB60RgXzeDEK1utrCMV8kHqVXDZJ4G9vjJBa]ulibasic@r...[/url
    > Sent: Wednesday, June 12, 2002 7:14 AM
    > To: basicstamps@yahoogroups.com
    > Subject: [noparse][[/noparse]basicstamps] Tricky Random Question
    >
    >
    > Hi everyone,
    >
    > I am working on a project and I have some random problem that
    > might be easy for you bit-wizards but seems too tricky for me:
    >
    > I want to play 90 different files from a quadravox-soundchip.
    > (it is a poem spoken by a friend of mine). The aim is to play
    > all 90 sounds in a random order and next time in another
    > order. Always all 90 sounds shall be used. Aditionally no
    > order should appear twice, so that after a (very) long time
    > every possible poem made out of the 90 words should have been
    > played once.
    >
    > How would I program this?
    >
    > Thanx a lot, Uli
    >
    >
    > [noparse][[/noparse]Non-text portions of this message have been removed]
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the
    > Subject and Body of the message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to
    > http://docs.yahoo.com/info/terms/
    >
  • ArchiverArchiver Posts: 46,084
    edited 2002-06-12 14:00
    Keep in mind that the RANDOM function is actually quasi-random since it is
    algorithmically generated. You can add some randomness by involving some
    human interaction. At the beginning of your program you can have a loop that
    waits on some human input while continuously calling the RANDOM function. If
    you don't shake things up like this, you'll get the same results every time.

    Then, you'll need 12 bytes (96 bits) to keep track of which file has been
    played and a couple of routines (I would call them Mark and IsMarked) to
    manage the bits. It really shouldn't be too tough -- about a pizza's worth
    of programming time....

    -- Jon Williams
    -- Parallax


    In a message dated 6/12/02 7:20:26 AM Central Daylight Time,
    ulibasic@r... writes:


    > Hi everyone,
    >
    > I am working on a project and I have some random problem that might be easy
    > for you bit-wizards but seems too tricky for me:
    >
    > I want to play 90 different files from a quadravox-soundchip. (it is a poem
    > spoken by a friend of mine). The aim is to play all 90 sounds in a random
    > order and next time in another order.
    > Always all 90 sounds shall be used. Aditionally no order should appear
    > twice, so that after a (very) long time every possible poem made out of the
    > 90 words should have been played once.
    >
    > How would I program this?
    >
    >




    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2002-06-12 20:46
    >Aditionally no order should appear
    >twice, so that after a (very) long time every possible poem made out of the
    >90 words should have been played once.

    (very) long time--90 factorial is about 15 followed by 137 zeros.
  • ArchiverArchiver Posts: 46,084
    edited 2002-06-12 22:39
    I can't think of any way (with a Stamp anyway) you can keep track of all the
    possible versions of the poem to make sure you haven't already played one.
    Get your calculator out and see if you can figure out how many versions
    there are -- 90x89x88x87... all the way to 2.

    With this being said, you need to generate a list of 90 exclusive random
    numbers -- this will determine what order to play the pieces in. One way to
    do this is to generate a random number then verify it hasn't already been
    used. The way to do this is generate an array of 90 single bit variables and
    set each bit to a one as the number is used. Each time you generate a random
    number between 1 and 90 you check the array, and if the number has been
    used, get another.



    > I am working on a project and I have some random problem that might be
    easy
    > for you bit-wizards but seems too tricky for me:
    >
    > I want to play 90 different files from a quadravox-soundchip. (it is a
    poem
    > spoken by a friend of mine). The aim is to play all 90 sounds in a random
    > order and next time in another order.
    > Always all 90 sounds shall be used. Aditionally no order should appear
    > twice, so that after a (very) long time every possible poem made out of
    the
    > 90 words should have been played once.
  • ArchiverArchiver Posts: 46,084
    edited 2002-06-13 01:20
    Hi Uli;

    If you are looking to see how many time it will take to get all of the
    possible combinations it is;

    1.485715964481761497309522733621e+138 the formula is n! on most calculators
    or 90*89*...*1

    this is a very large number, and I do not think it will ever be possible to do
    with the Basic Stamp because of
    it's size alone. I think you will get an overflow error before it is finished.

    Have Fun !!
    Dale Fleischmann

    ulibasic wrote:

    > Hi everyone,
    >
    > I am working on a project and I have some random problem that might be easy
    > for you bit-wizards but seems too tricky for me:
    >
    > I want to play 90 different files from a quadravox-soundchip. (it is a poem
    > spoken by a friend of mine). The aim is to play all 90 sounds in a random
    > order and next time in another order.
    > Always all 90 sounds shall be used. Aditionally no order should appear
    > twice, so that after a (very) long time every possible poem made out of the
    > 90 words should have been played once.
    >
    > How would I program this?
    >
    > Thanx a lot, Uli
    >
    > [noparse][[/noparse]Non-text portions of this message have been removed]
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the Subject and Body
    of the message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
  • ArchiverArchiver Posts: 46,084
    edited 2002-06-13 01:29
    This is simple. Just set up an array of 90 boolean (True/False or 0/1
    values)
    This will keep track of what has already been played
    Also a variable of how many more are still to be played

    I am not much of a Basic stamp programmer, so here is a sub routine in a
    standard VB type sub format

    Private Sub PlayRandom()
    Dim played(90,False) 'Just set the variable of 90 items to False (not been
    played)
    Var lefttogo=90 'Set the number of parts to be played
    Randomize Timer 'Seed the random generator with time data
    Do while lefttogo >0 'Loop until left to go = 0
    myrandom = int(rnd(1)*90)) 'Get a random value 0>=random=<89
    if played(myrandom) = False then 'If this bit has not bee played then...
    [noparse][[/noparse]PLAY THE TRACK # myrandom] 'Play the track
    Played(myrandom)=True 'Set Played to true for this track
    lefttogo = lefttogo - 1 'Decrement the number of bits still to play
    end if
    Loop 'Loop back to Do statement
    End Sub

    I think this is correct
    With tht nature of this code, the more 'bits' that have ben played, the
    longer it will take to find the next one to play. Statistically, the loop
    will have to loop 90 times to select the last bit to play. - I have
    substituted program speed for simplicity and code size

    I'm sure you undestand how this works, and how to port it to a basic stamp,
    it is a fairly easy bit of code.

    Original Message
    From: "Dale Fleischmann" <fleidale@c...>
    To: <basicstamps@yahoogroups.com>
    Sent: Thursday, June 13, 2002 12:20 PM
    Subject: Re: [noparse][[/noparse]basicstamps] Tricky Random Question


    > Hi Uli;
    >
    > If you are looking to see how many time it will take to get all of the
    possible combinations it is;
    >
    > 1.485715964481761497309522733621e+138 the formula is n! on most
    calculators or 90*89*...*1
    >
    > this is a very large number, and I do not think it will ever be possible
    to do with the Basic Stamp because of
    > it's size alone. I think you will get an overflow error before it is
    finished.
    >
    > Have Fun !!
    > Dale Fleischmann
    >
    > ulibasic wrote:
    >
    > > Hi everyone,
    > >
    > > I am working on a project and I have some random problem that might be
    easy
    > > for you bit-wizards but seems too tricky for me:
    > >
    > > I want to play 90 different files from a quadravox-soundchip. (it is a
    poem
    > > spoken by a friend of mine). The aim is to play all 90 sounds in a
    random
    > > order and next time in another order.
    > > Always all 90 sounds shall be used. Aditionally no order should appear
    > > twice, so that after a (very) long time every possible poem made out of
    the
    > > 90 words should have been played once.
    > >
    > > How would I program this?
    > >
    > > Thanx a lot, Uli
    > >
    > > [noparse][[/noparse]Non-text portions of this message have been removed]
    > >
    > > To UNSUBSCRIBE, just send mail to:
    > > basicstamps-unsubscribe@yahoogroups.com
    > > from the same email address that you subscribed. Text in the Subject
    and Body of the message will be ignored.
    > >
    > >
    > > Your use of Yahoo! Groups is subject to
    http://docs.yahoo.com/info/terms/
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the Subject and
    Body of the message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
    >
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2002-06-13 01:43
    I also suggested this method, but later realized there is a slight drawback
    due to wanting real-time speech.

    The drawback to keeping track of this real time and playing the words as
    they are selected, rather than building an array of values from 1 to 90 and
    playing the words off this list, is that as you start to use up all the
    numbers the loop gets slower and slower, and the speech gets choppy.

    *********

    > This is simple. Just set up an array of 90 boolean (True/False or 0/1
    > values)
    > This will keep track of what has already been played
    > Also a variable of how many more are still to be played
    >
    > I am not much of a Basic stamp programmer, so here is a sub routine in a
    > standard VB type sub format
  • ArchiverArchiver Posts: 46,084
    edited 2002-06-13 01:53
    Another option then would be to process the subroutine first, storing the
    output values in an array, *THEN* playing the audio files realtime.

    Regards

    John

    Original Message
    From: "Rodent" <daweasel@s...>
    To: <basicstamps@yahoogroups.com>
    Sent: Thursday, June 13, 2002 12:43 PM
    Subject: Re: [noparse][[/noparse]basicstamps] Tricky Random Question


    > I also suggested this method, but later realized there is a slight
    drawback
    > due to wanting real-time speech.
    >
    > The drawback to keeping track of this real time and playing the words as
    > they are selected, rather than building an array of values from 1 to 90
    and
    > playing the words off this list, is that as you start to use up all the
    > numbers the loop gets slower and slower, and the speech gets choppy.
    >
    > *********
    >
    > > This is simple. Just set up an array of 90 boolean (True/False or 0/1
    > > values)
    > > This will keep track of what has already been played
    > > Also a variable of how many more are still to be played
    > >
    > > I am not much of a Basic stamp programmer, so here is a sub routine in a
    > > standard VB type sub format
    >
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the Subject and
    Body of the message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
    >
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2002-06-13 05:50
    Tracy's and Dale's comments concerning the number of combinations bring
    to mind the engineering slogan: a job that's not worth doing is not
    worth doing well.

    Dennis

    Original Message
    From: Tracy Allen [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=F4i4TpEeeoTGUZmNjcRohiCRyNgETKr1rbGrne-0gxBpaiRevRLKZDg98nBsclJsGKzT6QZXriKcig]tracy@e...[/url
    Sent: Wednesday, June 12, 2002 12:47 PM
    To: basicstamps@yahoogroups.com
    Subject: Re: [noparse][[/noparse]basicstamps] Tricky Random Question


    >Aditionally no order should appear
    >twice, so that after a (very) long time every possible poem made out of

    >the 90 words should have been played once.

    (very) long time--90 factorial is about 15 followed by 137 zeros.


    To UNSUBSCRIBE, just send mail to:
    basicstamps-unsubscribe@yahoogroups.com
    from the same email address that you subscribed. Text in the Subject
    and Body of the message will be ignored.


    Your use of Yahoo! Groups is subject to
    http://docs.yahoo.com/info/terms/
  • ArchiverArchiver Posts: 46,084
    edited 2002-06-13 14:24
    --- In basicstamps@y..., "Dennis P. O'Leary" <doleary@h...> wrote:
    > Tracy's and Dale's comments concerning the number of combinations
    bring
    > to mind the engineering slogan: a job that's not worth doing is not
    > worth doing well.

    It occurs to me that alot of focus is being put on never repeating a
    sequence of words...While that is ideal, this whole project would be
    simplified by simply augmenting the random function, as someone
    suggested, and picking the words one at a time until they are all
    used...I seem to recall someone suggested setting bits for each
    word? I don't recall which stamp was being used in the original
    design, but is it possible to copy the pointers to the 90 words on
    the chip into an array and randomize it? I've used this method in
    QB4.5 (QuickBASIC) to randomize word lists in old word games.

    Chris
  • ArchiverArchiver Posts: 46,084
    edited 2002-06-13 14:28
    Thanks Chris,
    At least *someone* thought my idea was worthy of more than a 1 second glance

    Regards

    John Burns
    f i l e - i t @ x t r a . c o . n z
    01000001 01100100 00100000 01000001 01110011 01110100 01110010 01100001
    00100000 01110000 01100101 01110010 00100000 01000001 01110010 01100100
    01110101 01100001

    Original Message
    From: "Knight_Designs" <knight_designs@y...>
    To: <basicstamps@yahoogroups.com>
    Sent: Friday, June 14, 2002 1:24 AM
    Subject: [noparse][[/noparse]basicstamps] Re: Tricky Random Question


    > --- In basicstamps@y..., "Dennis P. O'Leary" <doleary@h...> wrote:
    > > Tracy's and Dale's comments concerning the number of combinations
    > bring
    > > to mind the engineering slogan: a job that's not worth doing is not
    > > worth doing well.
    >
    > It occurs to me that alot of focus is being put on never repeating a
    > sequence of words...While that is ideal, this whole project would be
    > simplified by simply augmenting the random function, as someone
    > suggested, and picking the words one at a time until they are all
    > used...I seem to recall someone suggested setting bits for each
    > word? I don't recall which stamp was being used in the original
    > design, but is it possible to copy the pointers to the 90 words on
    > the chip into an array and randomize it? I've used this method in
    > QB4.5 (QuickBASIC) to randomize word lists in old word games.
    >
    > Chris
    >
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the Subject and
    Body of the message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
    >
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2002-06-13 17:33
    --- File-IT Software Productions Ltd
    <file-it@i...> wrote:
    > Thanks Chris,
    > At least *someone* thought my idea was worthy of
    > more than a 1 second glance

    Well John, it's the only useable solution that I can
    see here...All the other methods will pretty much be
    out of the range of the BS2's capabilities, while
    being a little "overkill" for what is needed (IMHO).

    Chris



    __________________________________________________
    Do You Yahoo!?
    Yahoo! - Official partner of 2002 FIFA World Cup
    http://fifaworldcup.yahoo.com
  • ArchiverArchiver Posts: 46,084
    edited 2002-06-13 18:00
    Hi Uli,

    I didn't mean by my comment to stifle creativity among stampers,
    particularly on projects that combine poetry or art or music and clever
    elctronics.

    But from service on a number of (US) governmental advisory or review
    committees, I'm frequently reminded that largely impossible projects
    acquire funding and momentum before a watchdog group points out some
    obvious flaws, as Tracy and Dale did on this otherwise admirable
    project.

    Regards,
    Dennis

    Original Message
    From: ulibasic [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=3_4POioCX_YkM0Vh6jnIbEweMEB6p7PDooCy5WUPSQ58geO6gii0_fdO6S6AWvNhNq3ChQS5y8icZpsLdBsbsXkUpBF8_SKIhyrBLss]ulibasic@r...[/url
    Sent: Thursday, June 13, 2002 7:45 AM
    To: basicstamps@yahoogroups.com
    Subject: AW: [noparse][[/noparse]basicstamps] Re: Tricky Random Question


    Hey all you people,

    hey John, it is worth more than a glance, all of you helped me a lot,
    really!!! I like the idea of finding the order first and then play the
    poem because a pause of some seconds before each new version is good
    anyways.

    I think I didnt reflect on the impossibility of keeping track of all the
    versions already played, maybe it is almost Goedel stuff: there can be
    no system that is smaller than the number of possibillities that keeps
    track of them... (maybe you can say that in better English... :-)

    As far as Dennis is concerned: if this sentence is true I have spent all
    my life doing things that are not worth doing them good...see for
    yourself on www.u-winters.de


    Thank you all, Uli
  • ArchiverArchiver Posts: 46,084
    edited 2002-06-13 23:05
    As I said the first time, you need to generate a list of *exclusive* random
    numbers and use this list to sequence the words. This is how cards are
    shuffled in a card game.


    > At least *someone* thought my idea was worthy of more than a 1 second
    glance

    > > It occurs to me that alot of focus is being put on never repeating a
    > > sequence of words...While that is ideal, this whole project would be
    > > simplified by simply augmenting the random function, as someone
    > > suggested, and picking the words one at a time until they are all
    > > used...I seem to recall someone suggested setting bits for each
    > > word? I don't recall which stamp was being used in the original
    > > design, but is it possible to copy the pointers to the 90 words on
    > > the chip into an array and randomize it? I've used this method in
    > > QB4.5 (QuickBASIC) to randomize word lists in old word games.
Sign In or Register to comment.