-
December 12th, 2008, 08:18 AM
#1
C languege (auto ganerate number)
How to use C languege to auto generate number???
example:
1001
1002
than 1st number is fit(1002)
by not using this matter:
Code:
int id=101;
.........
id++;
pls help!!!
-
December 12th, 2008, 08:29 AM
#2
Re: C languege (auto ganerate number)
When you say "auto-generate" I think of random numbers, but it looks like you're talking about incrementing numbers. Can you be a little more specific on exactly what you want?
-
December 12th, 2008, 09:29 AM
#3
Re: C languege (auto ganerate number)
Originally Posted by CreganTur
When you say "auto-generate" I think of random numbers, but it looks like you're talking about incrementing numbers. Can you be a little more specific on exactly what you want?
yayaya thx
can you tech me how to write the "random numbers" segment
example???
yes i wan that "random pick number"!!!
-
December 12th, 2008, 09:33 AM
#4
Re: C languege (auto ganerate number)
yes i wan that "random pick number"!!!
Take a look at srand and rand.
-
December 12th, 2008, 10:04 AM
#5
Re: C languege (auto ganerate number)
Absolutely, I don't think that I understand what you said all.
Due to my understand It's my answer:
You can use a large number begin with 1
ex: id = 1000;
And after that you can general other number so that it's less than id
ex: id2 = rand()%id;
And finally you can sum both of them
ex: result = id + id2;
My English is very bad. So tell me if Something I talked make u confuse.
My Ebook Store: www.coding.vn/book.php
-
December 12th, 2008, 10:13 AM
#6
Re: C languege (auto ganerate number)
Originally Posted by Skizmo
thx i know ald
Code:
/* RAND.C: This program seeds the random-number generator
* with the GetTickCount, then displays 10 random integers.
*/
#include <stdlib.h>
#include <stdio.h>
#include <winbase.h>
void main( void )
{
int i;
/* Seed the random-number generator with GetTickCount so that
the numbers will be different every time we run.
*/
srand(
GetTickCount()
);
/* Display 10 numbers. */
for(
i = 0; i < 10;i++
)
printf(
"%6d\n", rand()
);
}
-
December 12th, 2008, 10:58 AM
#7
Re: C languege (auto ganerate number)
I have no idea what language you're speaking.
-
December 12th, 2008, 03:49 PM
#8
Re: C languege (auto ganerate number)
you can also to customize generate number :
Code:
int
GetRandomNumber(int nLowNumber, int nHighNumber)
{
const int IMax = dwLowNumber;
const int IMin = dwHighNumber;
return (IMin + rand() % (IMax - IMin));
}
// Example Usage : generate number between ( 12 ... 102)
// int randnum = GetRandomNumber ( 12, 102 ) ;
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|