How do i use the random number function?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Chris Winton
    New Member
    • Jan 2011
    • 22

    How do i use the random number function?

    Hello I'm using the random number function to try to multiply the values in the array O by a random number but receive the error - invalid operands to binary error*. Thanks for any help.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    double O[1][6] = {{1, 1, 1, 1, 1, 1}};
    
    /*********** random number generator *******************/
    double srandom()   
    {
    return 2*((rand()/(double)RAND_MAX) - 0.5);
    }
    /**************** main ********************************/
    int main()
    {
    double z [1][6];
    zrandom = O  * frand();
    }
    Cheers
    Chris
  • horace1
    Recognized Expert Top Contributor
    • Nov 2006
    • 1510

    #2
    in line
    Code:
    zrandom = O  * frand();
    you don't have am identifier zrandom (should it be z?) and O is an array so needs indexes, e.g. O[1][2]

    Comment

    • Chris Winton
      New Member
      • Jan 2011
      • 22

      #3
      Ah that would explain alot, also it was indexes for z and o that were causing the issues. Thanks for your help.

      Comment

      Working...