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

What is returned ?

Hi,

I have a C question.

Let's assume MT is not defined

int holdrand = 1;

int __cdecl rand (void)
{
#ifdef _MT
_ptiddata ptd = _getptd();
return( ((ptd->_holdrand = ptd->_holdrand * 214013L + 2531011L) >> 16)
&
0x7fff );
#else /* _MT */
return(((holdrand = holdrand * 214013L + 2531011L) >> 16) & 0x7fff);
#endif /* _MT */
}

I have trouble understanding what this function returns.

My confusion is with this line:

return(((holdrand = holdrand * 214013L + 2531011L) >> 16) & 0x7fff);

Apperently this line assigns some value to holdrand.

Something like:

holdrand becomes holdrand * blablabla etc.

But what is returned ?

I think it returns holdrand after the calculation.

But.... if that would be true... then this random number generator simply
uses the previous rand value to calculate the next one ?

Weird... I don't understand it... so that's why I ask this newsgroup =D

Bye,
Skybuck
Nov 14 '05 #1
1 2091
Skybuck Flying wrote:
...
My confusion is with this line:

return(((holdrand = holdrand * 214013L + 2531011L) >> 16) & 0x7fff);

Apperently this line assigns some value to holdrand.
This is equivalent to

holdrand = holdrand * 214013L + 2531011L;
return (holdrand >> 16) & 0x7fff;
Something like:

holdrand becomes holdrand * blablabla etc.
Yes, 'holdrand' becomes 'holdrand * 214013L + 2531011L'.
But what is returned ?

I think it returns holdrand after the calculation.
No. It returns '(holdrand >> 16) & 0x7fff', where 'holdrand' holds the
new value, i.e. value assigned by the inner assignment operator.
But.... if that would be true... then this random number generator simply
uses the previous rand value to calculate the next one ?
Of course. That's how oracle-type pseudo-random number generators work.
They are stateful functions, which means that they generate the new
state based on the previous state.
Weird... I don't understand it... so that's why I ask this newsgroup =D


What exactly don't you understand?

--
Best regards,
Andrey Tarasevich
Nov 14 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: lawrence | last post by:
I posted before, but have now narrowed my problem down to this method. At the start of the method, I test to make sure that I have a resource, a pointer to data returned from a database. This test...
10
by: Brad Tilley | last post by:
Is there an easier way to do this: def print_whats_returned(function): print function print type(function)
1
by: Liza | last post by:
Hi guys, can anyone explain line number 5 to me. i don't quite understand what is going on there and why. 1 <script language="vbscript" runat="server">sub Application_OnStart 2 getcustomers...
5
by: Franco, Gustavo | last post by:
Hi, I have a question, and please I need a answer. How can I finalize a thread running with Application.Run (I need the message loop!!!) without call Thread.Abort?. I want to call...
18
by: Jm | last post by:
Hi all I feel stupid for asking this, but i just went to use the left() function from vb6 only to find it doesnt do what it used to under .NET. Im assuming theres something else now im meant to...
16
by: Bob Hairgrove | last post by:
Consider the classic clone() function: class A { public: virtual ~A() {} virtual A* clone() const = 0; }; class B : public A { public:
82
by: quiberon2 | last post by:
Hi, Sorry if it might be a stupid question but what should returns malloc(0) ? void *ptr = malloc(0); I am running gcc 3.3.5 and a non-null address is returned. ( in the compiler that I am...
14
by: salad | last post by:
XML seems to be a hot technology buzzword. And it appears XML is supported in A2003. I am wondering if it could be used in the following scenario. I create an order record for the customer. ...
4
by: grizggg | last post by:
I have searched and not found an answer to this question. I ran upon the following statement in a *.cpp file in a member function: static const char * const pacz_HTMLContentTypeHeader =...
16
by: John Doe | last post by:
Hi, I wrote a small class to enumerate available networks on a smartphone : class CNetwork { public: CNetwork() {}; CNetwork(CString& netName, GUID netguid): _netname(netName),...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.