473,385 Members | 1,872 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,385 software developers and data experts.

Calling the time function in a C program

I have a program that I needed to create for a homework that is an Operating System Simulator. It's not as cool as it sounds. When I run it,

Expand|Select|Wrap|Line Numbers
  1.  
  2.   long now ;
  3.  
  4.   srand( system( "time(&now)" ) );
  5.  
  6.  
Is supposed to create a value that will initialize the "system clock" ( a static int ).

The program runs and does what it is supposed to, except there is no randomness in the results ( there should be differences in the amount of "time units", which are measured in blocks of time that is affected by this function call I believe.

Anyone help me make sure I'm doing this right? It's supposed to put that random # in the variable "now".
Mar 7 '08 #1
5 1592
I have my entire code if someone wants to read it and tell me why I'm not getting random outputs, that works too.
Mar 7 '08 #2
gpraghuram
1,275 Expert 1GB
I have a program that I needed to create for a homework that is an Operating System Simulator. It's not as cool as it sounds. When I run it,

Expand|Select|Wrap|Line Numbers
  1.  
  2.   long now ;
  3.  
  4.   srand( system( "time(&now)" ) );
  5.  
  6.  
Is supposed to create a value that will initialize the "system clock" ( a static int ).

The program runs and does what it is supposed to, except there is no randomness in the results ( there should be differences in the amount of "time units", which are measured in blocks of time that is affected by this function call I believe.

Anyone help me make sure I'm doing this right? It's supposed to put that random # in the variable "now".

are you calling seed() function before calling this?

Raghuram
Mar 7 '08 #3
No, I'm confused by this whole setup. It is from a book and it is 20 years old and they don't explain their code. Our job is to type it in and get it to work in ANSI C and they throw little things like this in there that I can't quite figure out.
Mar 7 '08 #4
Banfa
9,065 Expert Mod 8TB
are you calling seed() function before calling this?
srand IS the seed function for the PRNG.
Mar 7 '08 #5
Banfa
9,065 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1.  
  2.   long now ;
  3.  
  4.   srand( system( "time(&now)" ) );
  5.  
  6.  
This code is not right I think you mean

Expand|Select|Wrap|Line Numbers
  1.  
  2.   long now ;
  3.  
  4.   srand( time(&now) );
  5.  
But you should read up on system and time so that you understand exactly what they do.
Mar 7 '08 #6

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

Similar topics

2
by: Marc Shapiro | last post by:
I am relatively new to python (I have used it on and off for a few small projects over the last few years) so I imagine that what I am trying to do has already been done, but practical experience,...
2
by: Shailan | last post by:
Hi Im having trouble with the following code that seems to be behave differently when called from the browser as opposed to the command line. The calling script is a cgi that forks, with the...
3
by: Ken | last post by:
hello, I would to know if it is possible to call an object in a function within a class. Meaning , In a class, A function X calling onto a function Y, and function Y we want one of the two...
4
by: Sivakumar Shanmugam | last post by:
Group.. We are running on db2 UDF V8 on Sun solaris platform. I created an UDF which calles a C-routine(SQL_API_FN). This C-routine in turn calls an external C-function. The C-function is provided...
9
by: kernelxu | last post by:
hi,everybody. I calling function setbuf() to change the characteristic of standsrd input buffer. some fragment of the progrem is: (DEV-C++2.9.9.2) #include <stdio.h> #include <stdlib.h> int...
5
by: Dave | last post by:
does calling a regular function cost any cpu time? In other words, is it faster to write the code of two functions into main(), or is it the exact same thing as calling two functions. I know its...
4
by: Peter Afonin | last post by:
Hello, I have a weirdest issue I've ever had. I have a function that enters some data into the Oracle table and returns the sequential row number for the new record (autonumber): Private...
7
by: Kenneth Brody | last post by:
The recent thread on "query about main()" got me thinking... As I recall, calling a function with the wrong parameters causes undefined behavior. (These all assume that no prototype of foo()...
11
by: ypjofficial | last post by:
Hello All, So far I have been reading that in case of a polymorphic class ( having at least one virtual function in it), the virtual function call get resolved at run time and during that the...
4
by: Edwin Gomez | last post by:
I'm a C# developer and I'm new to Python. I would like to know if the concept of Asynchronous call-backs exists in Python. Basically what I mean is that I dispatch a thread and when the thread...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.