How to generate random number numbers in c iteratively, without having the same sequence?
I want to generate say 10 good random numbers 10 times in one execution, without pattern or sequence.
How should i do that?
Somebody help me!
How to generate random number numbers in c iteratively, without having the same sequence?
I want to generate say 10 good random numbers 10 times in one execution, without pattern or sequence.
How should i do that?
Somebody help me!
The rand() function. FAQ > How do I... (Level 1) > Generate random numbers?
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
plus, you can use "search" to see the previous posts about the topic!
If you don't want patterns or sequences, you could get a Geiger counter and attach it to your computer (might take a bit of socket/driver work), then place it near a mildly radioactive source (in the basement, for example). You can then use the bit patterns to generate very random numbers, with no discernible pattern or sequence.
Code:#include <stdio.h> void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){ puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9 /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i] ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][ t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}
I don't have a Shrödinger Cat, but I do have a Shrödinger USB Mouse.
Well it seems like it, it sometimes just hyperspaces the cursor to a random spot on the screen - not good if you're dragging and dropping a bunch of files at the time
IMO, links to the rand() FAQ should point to a random FAQ
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.