   question about generate random number in c++?
  I am trying to generate 2 random numbers at the time is generate.  However, it return only one number  to main(). Does anyone know hat''s wrong with my code?below is my code of function start:----------------------------------int  start(int max){   srand(time(0) % max);   int number1;   for (int i=0; i   
  Only call srand() to seed the random number generator at the beginning of the program, not everytime you want a random number, and just seed it with time(0), then you should get some pseudorandom numbers. ;  I could be wrong but I belive a function can only return one value thus the second value is ignored.  Also you srand should be called at the start of the program and not each time.  As a side note does anyone know if you can use a fixed seed at some parts of your code and random seed at other parts?   -----------------------------------------------------Writer, Programer, Cook, I''m a Jack of all TradesCurrent Design projectChaos Factor Design Document ;  as TechnoGoth said, you can only return one variable from a function. the only reason that you didn''t get an error is because the comma (,) operator is valid in C++ (it evaluates both parts before and after it, but only returns the last one).quote:Original post by TechnoGoth  As a side note does anyone know if you can use a fixed seed at some parts of your code and random seed at other parts?i don''t think so... not with the default psuedo-random number generator anyway.there is a class implementation of the Mersenne Twister, so you could make multiple object instances off the class and seed each one differently... you could try that. sorry but i have no link ;  void Return2RandomNums(int *num1, int *num2) {    *num1 = WhateverYourRandFuncIs();    *num2 = WhateverYourRandFuncIs();    return;}call this with:int x,y;Return2RandomNums(&x, &y); ;  Or better (since this is c++):void Return2RandomNums(int& num1, int& num2) {num1 = WhateverYourRandFuncIs();num2 = WhateverYourRandFuncIs();return;}  Enigma ;  Link to <a href="http://www.math.keio.ac.jp/~matumoto/emt.html">Mersene Twister</a> pagequote:there is a class implementation of the Mersenne Twister, so you could make multiple object instances off the class and seed each one differentlyWhy would anyone want to be-able to do that if they want entirely random numbers ? surely you have a danger of predictable numbers that way... ;  Damn it! try with capitals in my tags like others (...or can''t AP''s post links ?)Link to <A HREF="http://www.math.keio.ac.jp/~matumoto/emt.html">Mersene Twister</A> page ;quote:Original post by Tenchi  return number1, number2;   You cant return two values at once.  The compiler treats the comma as the sequential evaluation operator.  That line of code is essentially equivalent to return number2; ;quote:Original post by Anonymous Poster  Why would anyone want to be-able to do that if they want entirely random numbers ? surely you have a danger of predictable numbers that way...   it would be good for, say, randomly generated maps (that you don''t want to change mid-game)... instead of saving the entire map for the next time, you just save the seed and generate it again.anonymous posters can''t use HTML, btw. 