The random function, generates the same values each the time program is run.. Any other function to output random numbers, each time the program is run ??
Master Mascus 0 Light Poster
Recommended Answers
Jump to PostThe usual method is seeding rand() with the current time:
#include <stdio.h> #include <stdlib.h> #include <time.h> int main(void) { int i; srand((unsigned)time(NULL)); for (i = 0; i < 10; i++) printf("%3d", rand() % 100); putchar('\n'); return 0; }
Jump to Postbut if i need to apply that in my work, how can i do it ??
Generate the numbers, then shuffle them randomly. For example, see this thread, or this thread.
Jump to Posthowever if all the numbers are not in the requirements random shuffle wont work.
Your use of the word "requirements" is confusing. Can you elaborate?
Jump to PostWhat I mean is that suppose you want 6 nos from a range of 1-1000,random shuffle would have to be modified.
There's nothing about that use case that would require random shuffle to be modified. Taking a sample of 6 numbers from a randomly shuffled array of 1000 is trivial …
Jump to Posthow can i compare the array of values?
What do you mean by compare them? Are you trying to match the two arrays in both values and order? Just values? What exactly are you looking for in the comparison?
All 18 Replies
Narue 5,707 Bad Cop Team Colleague
Master Mascus 0 Light Poster
arghasen 0 Light Poster
Master Mascus 0 Light Poster
Narue 5,707 Bad Cop Team Colleague
arghasen 0 Light Poster
Narue 5,707 Bad Cop Team Colleague
Master Mascus 0 Light Poster
arghasen 0 Light Poster
Narue 5,707 Bad Cop Team Colleague
Master Mascus 0 Light Poster
Narue 5,707 Bad Cop Team Colleague
Master Mascus 0 Light Poster
Narue 5,707 Bad Cop Team Colleague
ashok1514 -4 Newbie Poster
Narue 5,707 Bad Cop Team Colleague
Master Mascus 0 Light Poster
Narue 5,707 Bad Cop Team Colleague
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.