Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-interest Archive, January 2008
Getting the current qrand seed value


Message 1 in thread

Hi Everybody, 

I am converting Delphi code that effectively does the following: 

save = current_rand_seed;
qsrand( new_value );
...
	qrand();
...
qsrand( save );

In other words, the code wants a reproducible sequence of random values, without causing problems elsewhere. I'm checking whether this is actually required to be converted. 

If it is required, how do I obtain the current seed value in Qt? I understand that this will only be for the current thread. 

Thanks in advance, 

Tony Rietwyk

--
 [ signature omitted ] 

Message 2 in thread

Tony Rietwyk wrote:
> Hi Everybody, 
> 
> I am converting Delphi code that effectively does the following: 
> 
> save = current_rand_seed;
> qsrand( new_value );
> ...
> 	qrand();
> ...
> qsrand( save );
> 
> In other words, the code wants a reproducible sequence of random values, without causing problems elsewhere. I'm checking whether this is actually required to be converted. 
> 
> If it is required, how do I obtain the current seed value in Qt? I understand that this will only be for the current thread. 
> 
> Thanks in advance, 
> 
> Tony Rietwyk
> 
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
> 
> 
> 


Greetings,

Before anything else i want to clarify that Qt does not provide random 
number generator functionality. The random number generator is provided 
by standard c++ (stdlib.h). So you have to check out the c++ 
documentation to find out what exactly you need although I think that 
srand() function will suit you.

Check out the tic tac toe example of qt assistant and the following link 
for further information.
http://www.cplusplus.com/reference/clibrary/cstdlib/srand.html

Regards,
Iosif A. Osman

--
 [ signature omitted ] 

Message 3 in thread

> -----Original Message-----
> From: Iosif A. Osman [mailto:osman@xxxxxxxxxxxx] 
> Sent: Wednesday, 2 January 2008 19:08
> To: qt-interest@xxxxxxxxxxxxx
> Subject: Re: Getting the current qrand seed value
> 
> 
> Tony Rietwyk wrote:
> > Hi Everybody, 
> > 
> > I am converting Delphi code that effectively does the following: 
> > 
> > save = current_rand_seed;
> > qsrand( new_value );
> > ...
> > 	qrand();
> > ...
> > qsrand( save );
> > 
> > In other words, the code wants a reproducible sequence of 
> random values, without causing problems elsewhere. I'm 
> checking whether this is actually required to be converted. 
> > 
> > If it is required, how do I obtain the current seed value 
> in Qt? I understand that this will only be for the current thread. 
> > 
> > Thanks in advance, 
> > 
> > Tony Rietwyk
> > 
> > --
> > To unsubscribe - send a mail to 
> qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the 
> subject or the body.
> > List archive and information: 
> http://lists.trolltech.com/qt-interest/
> > 
> > 
> > 
> 
> 
> Greetings,
> 
> Before anything else i want to clarify that Qt does not 
> provide random 
> number generator functionality. The random number generator 
> is provided 
> by standard c++ (stdlib.h). So you have to check out the c++ 
> documentation to find out what exactly you need although I think that 
> srand() function will suit you.
> 
> Check out the tic tac toe example of qt assistant and the 
> following link 
> for further information.
> http://www.cplusplus.com/reference/clibrary/cstdlib/srand.html
> 
> Regards,
> Iosif A. Osman

Hi Iosif, 

Thanks for responding. 

qrand and qsrand were added at version 4.2. I'm on 4.3.1. According to
Assistant, they provide thread-safe versions of the standard C routines that
you refer to. These only allow you to reset to the original compiled value -
by srand(1). 

Regards, 

--
 [ signature omitted ] 

Message 4 in thread

> Hi Iosif, 
> 
> Thanks for responding. 
> 
> qrand and qsrand were added at version 4.2. I'm on 4.3.1. According to
> Assistant, they provide thread-safe versions of the standard C routines that
> you refer to. These only allow you to reset to the original compiled value -
> by srand(1). 
> 
> Regards, 
> 
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
> 



Hi Tony,

I apologise for the mistake and for the confusion i may have caused. I 
am using an older version of qt.

Regards,
Iosif A. Osman

--
 [ signature omitted ]