@Don: How about this below...? #include<stdio.h> int main(int argc,char *argv[]) { int a; a=(argv[0]); printf("%d",a%10); getchar(); }
To get a random value b/w 0 to 100, we can use a%100 and soon for 0-1000..... What say guys..? On 8/1/11, Don <dondod...@gmail.com> wrote: > That's actually a big question, because computers are deterministic, > so it is hard to see how they could act randomly. > > There are all sorts of pseudo-random generators which will produce a > stream of output which appear more or less random. The larger and more > sophisticated ones produce much better results than the poorly > designed ones. Decades ago there was a "random" generator called randu > which was notoriously bad, but before people figured out how flawed it > was, hundreds of simulation studies had been performed with it, and > most ended up being rejected as invalid based on the poor statistical > qualities of randu. > > Today there are several high-quality generators, such as the Mersenne > Twister. George Marsaglia has designed several excellent generators, > as well as the Diehard battery of tests to measure the statistical > quality of any generator. > > However, you seem to be wanting a single number which will be > different each time you run a program. > > You could do something as simple as > > int random_value = 2 + (time() % 9); > > Or you could pick any well-known random generator, seed it, and use it > to produce what you need. > > To get you started, this function will produce a pseudo-random stream > of output in the range 0..65535 using Marsaglia's "multiply with > carry" algorithm. > > > unsigned int mwc() > { > static unsigned int x = time(0); > x = 63663 * (x&65535) + (x>>16); > return x&65535; > } > > Don > > On Jul 31, 4:39 am, Puneet Gautam <puneet.nsi...@gmail.com> wrote: >> Can we write a code to generate random numbers without using rand >> function..? >> >> Pls help me on this!! > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.