Thread: Randomize Varible

  1. #1
    Hussa
    Guest

    Randomize Varible

    How to randomize new varible?

    For Example:

    int r;
    r = random();
    r will be for example 43

    so I want varible array become: char hello_43[256];

    Example code please...


    Thanks.

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    not possible.
    variable names are a compile time thing. They cannot be chosen based on runtime decisions.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Registered User dizolve's Avatar
    Join Date
    Dec 2002
    Posts
    68
    You can't really do that.. unless there are preprocessor directives I'm not aware of. What reason do you have for needing this? Maybe someone can suggest an alternative route for you.

      __               &n bsp;      ___ & nbsp;       &nb sp;       &nbsp ;    
     /\ \  __    &nbs p;           /\_ \      &nbsp ;        & nbsp;     
     \_\ \/\_\  ____     _ __\//\ \    __  __&n bsp;    __   
     /'_` \/\ \/\_ ,`\  / __`\\ \ \  /\ \/\ \  /'__`\ 
    /\ \_\ \ \ \/_/  /_/\ \_\ \\_\ \_\ \ \_/ |/\  __/ 
    \ \___,_\ \_\/\____\ \____//\____\\ \___/ \ \____\
     \/__,_ /\/_/\/____/\/___/ \/____/ \/__/   \/____/
            &n bsp; I have a BAD figlet& nbsp;addiction.

  4. #4
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    While I don't think this is necessarily a great way to code, you could instead do 2 dimensional arrays.
    Code:
    char hello[100][256];
    int r;
    r = random()%100;  // get number between 0 and 99
    
    hello[r]="whatever";

  5. #5
    Hussa
    Guest

    ...

    Well, How can I use hello[1][256]; with cin.get()?


    For example:
    char wow[256];
    cout <<"Enter your name\n";
    cin.get(wow,256);


    How would I do that if it has wow[1][256] with cin.get?

  6. #6
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    I believe like this:
    Code:
    char wow[100][256];
    cout <<"Enter your name\n";
    cin.get(wow[1],256);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. randomize array blackjack c program
    By bazzano in forum C Programming
    Replies: 4
    Last Post: 09-01-2005, 02:05 PM
  2. accessing varible in a c++ class
    By jccharl in forum C++ Programming
    Replies: 1
    Last Post: 03-10-2004, 03:01 PM
  3. Varible is different once returned.
    By epoch in forum C++ Programming
    Replies: 2
    Last Post: 01-04-2003, 02:45 AM
  4. Problem with Visual C++ ( randomize function )!
    By marCplusplus in forum C++ Programming
    Replies: 2
    Last Post: 12-17-2001, 01:01 PM
  5. Randomize Number Function
    By beyonddc in forum C Programming
    Replies: 3
    Last Post: 12-10-2001, 04:31 AM