473,320 Members | 2,041 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

functions

how do we use the function randomize() to initialize randomization process?
Mar 14 '07 #1
7 1165
RedSon
5,000 Expert 4TB
Is randomize even a proper method. I thought it was srand and rand.
Mar 14 '07 #2
willakawill
1,646 1GB
how do we use the function randomize() to initialize randomization process?
this is from the help file in vc++
Expand|Select|Wrap|Line Numbers
  1. /* RAND.C: This program seeds the random-number generator
  2.  * with the time, then displays 10 random integers.
  3.  */
  4.  
  5. #include <stdlib.h>
  6. #include <stdio.h>
  7. #include <time.h>
  8.  
  9. int main( void )
  10. {
  11.    int i;
  12.  
  13.    /* Seed the random-number generator with current time so that
  14.     * the numbers will be different every time we run.
  15.     */
  16.    srand( (unsigned)time( NULL ) );
  17.  
  18.    /* Display 10 numbers. */
  19.    for( i = 0;   i < 10;i++ )
  20.       printf( "  %6d\n", rand() );
  21.    return 0;
  22. }
Mar 14 '07 #3
Is randomize even a proper method. I thought it was srand and rand.
Ok, so how do we use srand?
Mar 14 '07 #4
this is from the help file in vc++
Expand|Select|Wrap|Line Numbers
  1. /* RAND.C: This program seeds the random-number generator
  2.  * with the time, then displays 10 random integers.
  3.  */
  4.  
  5. #include <stdlib.h>
  6. #include <stdio.h>
  7. #include <time.h>
  8.  
  9. int main( void )
  10. {
  11.    int i;
  12.  
  13.    /* Seed the random-number generator with current time so that
  14.     * the numbers will be different every time we run.
  15.     */
  16.    srand( (unsigned)time( NULL ) );
  17.  
  18.    /* Display 10 numbers. */
  19.    for( i = 0;   i < 10;i++ )
  20.       printf( "  %6d\n", rand() );
  21.    return 0;
  22. }
Ok thanks, so why do you use function rand() in printf statement
Mar 14 '07 #5
willakawill
1,646 1GB
Ok thanks, so why do you use function rand() in printf statement
It is returning a random number. In this case the number is printed to the screen just for demonstration purposes. With code snippets like this you should copy them to your ide and compile them to see how it works. That is how I learn this stuff :)
Mar 14 '07 #6
It is returning a random number. In this case the number is printed to the screen just for demonstration purposes. With code snippets like this you should copy them to your ide and compile them to see how it works. That is how I learn this stuff :)
Ok thanks!
Mar 14 '07 #7
willakawill
1,646 1GB
You are very welcome :)
Mar 14 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: hokiegal99 | last post by:
A few questions about the following code. How would I "wrap" this in a function, and do I need to? Also, how can I make the code smart enough to realize that when a file has 2 or more bad...
99
by: David MacQuigg | last post by:
I'm not getting any feedback on the most important benefit in my proposed "Ideas for Python 3" thread - the unification of methods and functions. Perhaps it was buried among too many other less...
21
by: Rubén Campos | last post by:
I haven't found any previous message related to what I'm going to ask here, but accept my anticipated excuses if I'm wrong. I want to ask about the real usefulness of the 'inline' keyword. I've...
17
by: cwdjrxyz | last post by:
Javascript has a very small math function list. However there is no reason that this list can not be extended greatly. Speed is not an issue, unless you nest complicated calculations several levels...
2
by: Bryan Olson | last post by:
The current Python standard library provides two cryptographic hash functions: MD5 and SHA-1 . The authors of MD5 originally stated: It is conjectured that it is computationally infeasible to...
7
by: Tim ffitch | last post by:
Hi I have created a VB dll file that contains common functions I use across various projects in VB, Access and Excel. Rather than have to code the functions in each I decided to use the dll...
23
by: Timothy Madden | last post by:
Hello all. I program C++ since a lot of time now and I still don't know this simple thing: what's the problem with local functions so they are not part of C++ ? There surely are many people...
14
by: v4vijayakumar | last post by:
Why we need "virtual private member functions"? Why it is not an (compile time) error?
7
by: Immortal Nephi | last post by:
My project grows large when I put too many member functions into one class. The header file and source code file will have approximately 50,000 lines when one class contains thousand member...
6
KevinADC
by: KevinADC | last post by:
This snippet of code provides several examples of programming techniques that can be applied to most programs. using hashes to create unique results static variable recursive function...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.