View unanswered posts | View active topics It is currently Thu Jul 24, 2014 12:28 pm






Reply to topic  [ 11 posts ] 
1.38: randomize, srand: bad help and not ANSI compatible 
Author Message
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 1.38: randomize, srand: bad help and not ANSI compatible
there is still not enough help by code snippets and examples.

If I'm looking for srand and random, you should only have to put the cursor on this keyword in the source, and then press F1.

Then there should be a window with explanations and small code snippets, how to use each command and which variables have to be declarated.

One key word - One Page.

e.g. srand (seed): what is seed? I don't find anything!

A link to a related page ("more code examples") with extended and bigger source code examples may illustrate the usage. This might be a link to a sample program. for example.

Further on there should be a link from e.g. srand to random (and back) ("related functions"), where the other function is explained by examples ("close relatives").

Functions which are not similar or close to random and srand in any case should not be visible here at all (e.g., sin, cos, abs).

But another Link should guide to a page where an overview on a "distant relatives group" is listed (other math functions, hierarchical architecture).

By this system the Borland C++ or Delphi Help works excellent and is exemplary ! Maybe you wish to have a close look on this... 8)

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Last edited by Ford Prefect on Fri Jul 25, 2008 3:54 pm, edited 5 times in total.



Wed Jun 11, 2008 6:28 pm
Profile
Site Admin
Site Admin

Joined: Wed Jan 24, 2007 10:42 am
Posts: 601
Post 
I appreciate your input, but I need to remind you that Borland has hundreds of people working on their project, some specifically only on the help platform. We have 2 who work on everything.

The help is a significant upgrade over what was there. I wouldn't expect anything to the level of a professional development environment any time in the near future. Most of those help systems are custom developed whereas our help system is based off of windows-standard CHM/HTML based help.

_________________
Timothy Friez
ROBOTC Developer - SW Engineer
tfriez@robotc.net


Thu Jun 12, 2008 11:45 am
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 
aaaahhhm...ok.. :shock:

but could you plz explain the usage of

srand (seed): what is seed?

and for random there should be a usage with a REAL argument as well (not only INTEGER), in order to get a float value between 0...1

EDIT: sorry, random was a PASCAL command, not the C command .
the C command is rand(), but about rand() I can't find anything in the RobotC Help.


I still can't find anything about that...

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Last edited by Ford Prefect on Fri Jun 20, 2008 6:36 am, edited 2 times in total.



Fri Jun 13, 2008 6:08 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Jan 31, 2007 3:39 am
Posts: 299
Location: San Diego, California. USA
Post 
Seed is any whole number, it is used to decide where on a random number list the computer/nxt should start getting random numbers from. Computers have one huge list of random numbers and the seed is where the computer should start from. Its ironic really, that random numbers come from a predefined unchanging list lol, thats what the seed is for, so you can start in a different spot on the list. The list is huge, pages on pages, but sometimes its nice to know how the computer is really getting these "random" numbers. Thats the fun fact for the day lol B-)

Scott

_________________
Mmmm Legos B-)

My Robot Projects:
http://www.freewebs.com/robotprojects/


Wed Jun 18, 2008 4:04 pm
Profile WWW
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 
hi,
thx for this.
So srand(10) causes a different series of randomized numbers than srand(99).
So far so good.

But if I'll start in my program each time with the same randomization seed command, e.g.
srand(99),
won't the random function always produce the same series of random numbers, just if I hadn't called it ever at all?

Or is there a difference in the series, although the "seed " always is 99 ?(maybe, RobotC is the actaual date and time automatically to 99 as kind of variables ?)
In ANSI C this is not working automatically, here you have to initialize srand by sort of srand(time(0)) to get different series each time.

So, again:
what is seed needed for as a constant value in a routine, because from any runtime to any runtime there will be always 1 identical constant seed that leads to the identical series of pseudo random numbers ever and ever?

Is there a RobotC time function which you may use in order to get always different seeds from any runtime to the next?

Get what I mean?

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Last edited by Ford Prefect on Fri Jun 20, 2008 6:41 am, edited 6 times in total.



Thu Jun 19, 2008 3:13 am
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 
BTW:
Because this ROBOTC keyword random() reminded me more on Pascal than on C, I've been searching for some ANSI C definitions.
Here is what I found:

In ANSI C there is a function rand (NOT random), which produces random numbers between 0...RAND_MAX:

Quote:
Macro: RAND_MAX
The value of this macro RAND_MAX is an integer constant expression that represents the maximum possible value returned by the rand function. In the GNU library, it is 037777777, which is the largest signed integer representable in 32 bits. In other libraries, it may be as low as 32767.

Function: int rand ()
The rand function returns the next pseudo-random number in the series. The value is in the range from 0 to RAND_MAX.


why is RobotC in this point - again - different to ANSI C?
These special ROBOTC fantasy keywords make me really angry - how can one transfer any RobotC file to a standard ANSI C compiler (or reverse), if RobotC doesn't keep the standards??

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Thu Jun 19, 2008 6:37 am
Profile
Rookie
User avatar

Joined: Fri May 30, 2008 2:08 pm
Posts: 5
Post 
Ford Prefect wrote:
But if I'll start in my program each time with the same randomization seed command, e.g.
srand(99),
won't the random function always produce the same series of random numbers, just if I hadn't called it ever at all?


Hi Ford,

Sometimes you need a random series of numbers but you need that this series to be reproducible. The seed allows you to reproduce this series. I work with optimization algorithms for planning and scheduling the production of steel plants and this is a required feature for the algorithms that I use. I want to output the same result every time the user runs our programs with the same data.
If you want a different series of numbers each time that you run your program, just use the variable nSysTime as a seed.


Fri Jun 20, 2008 8:02 am
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 
hi,
that's a good reason - and a good idea, thanks a lot!

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Fri Jun 20, 2008 8:19 am
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 
@dick swan, @tfriez,
could you plz give a statement to these problems?
thx in advance!

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Tue Jul 08, 2008 2:45 am
Profile
Site Admin
Site Admin

Joined: Wed Jan 24, 2007 10:42 am
Posts: 601
Post 
The help documentation will be improved for the final release version of 1.40

_________________
Timothy Friez
ROBOTC Developer - SW Engineer
tfriez@robotc.net


Wed Jul 09, 2008 10:45 am
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post Re: 1.38: randomize, srand: bad help and not ANSI compatible
Dick Swan/Bug Tracker wrote:
There is already a definition for the standard C 'srand' function in ROBOTC. A "definition" form "rand" has now been added; it's actually a "#define". It will be in the next version of ROBOTC.

You can implement the enhancement now by editing the "RobotCIntrinsics.c" file wand replace the existing 'random' and 'srand' definition with the following.

intrinsic word function(random, opcdSourceRandom, 0x08000);
#define srand(seed) random[0] = seed
#define rand() random[0x7FFF]

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Wed Aug 20, 2008 12:54 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 11 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.