Thread: random things

  1. #1
    yes, I'm registered!!! algi's Avatar
    Join Date
    Nov 2004
    Location
    Ipswich
    Posts
    161

    random things

    does anybody know how to make a programme say random things, things you tell it to say.

  2. #2
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,090
    You can't make it say truly random things. You can write a program that has a set of possible things to say and have it randomly pick one.

  3. #3
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    I'm going to take this very literally for now. The FAQ has info about random. And you can play sounds using either a sound library, or via using an OS specific call. You can make list of sound files then use random to randomly play one of these sounds.

    Now I'm going to take a stab at guessing what you were asking. If you mean make the computer respond verbally in an intellegent way, yes, but judging by your poor ability to formulate a simple question I think neural programming may be a wee bit over your head.

  4. #4
    yes, I'm registered!!! algi's Avatar
    Join Date
    Nov 2004
    Location
    Ipswich
    Posts
    161
    sorry, I mean where you type an array of things to say or something, and the computer says one at random

  5. #5
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,090
    Just write the program yourself. Things you'd have to accomplish:
    - keeping track of what things the computer might say.
    - selecting one of those things at random.
    - outputting the selection.

    See if you can write in English (or whatever language) exactly what you want it to do. Give it as much detail as possible. This is the design phase of your program. Don't worry too much about how you'd do it in code, worry about how you would go about accomplishing that task in general. If you get stuck, then ask a question.

  6. #6
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Oh well then do as my first suggestion says. Have a library of sound files somewhere and do something simple like this:

    Example
    Code:
    void PlayRandomSoundClip(void) {
      const char *filenames[] = {"hello.wav", "good.wav", "whale call.wav"};
    
      PlaySound(filenames[rand()%3]); 
    }
    Do note that my sample is more pseudo code than anything.

  7. #7
    yes, I'm registered!!! algi's Avatar
    Join Date
    Nov 2004
    Location
    Ipswich
    Posts
    161
    thanks

  8. #8
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >does anybody know how to make a programme say random things
    Code:
    #include "iostream"
    #include <malloc.h>
    
    void main()
    {
      char *s = (char *)malloc(0);
      int i;
    
      gets(s);
      s[i] = s[i++] + s[i++];
      printf("%p -- %s -- %d", s, s);
    
      delete s;
    }
    My best code is written with the delete key.

  9. #9
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Not only random, but totally undefined (I count 6 undefined behaviours). Nice one, Prelude.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  10. #10
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Well if you want to just be random....

    Code:
    struct main(double ƒ0, int 2ndParameter) [
      if(ƒ0 != x)
         move eax, 2ndParamter + 3rdParameter;
       otherwise
         return new main("success");
    }

  11. #11
    yes, I'm registered!!! algi's Avatar
    Join Date
    Nov 2004
    Location
    Ipswich
    Posts
    161
    well i didn't mean completely random, but pick something random from an array

  12. #12
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >well i didn't mean completely random
    We know what you meant. But can you imagine how boring these forums would be if we never had fun and games?
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. random numbers
    By mesmer in forum C Programming
    Replies: 4
    Last Post: 10-24-2008, 01:22 PM
  2. Random number + guessing game trouble
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-08-2007, 03:33 AM
  3. Random word problem
    By goron350 in forum C++ Programming
    Replies: 2
    Last Post: 05-14-2005, 03:44 PM
  4. How do I restart a random number sequence.
    By jeffski in forum C Programming
    Replies: 6
    Last Post: 05-29-2003, 02:40 PM
  5. Generate random numbers in Lucky7 project using C#
    By Grayson_Peddie in forum C# Programming
    Replies: 1
    Last Post: 04-11-2003, 11:03 PM