Welcome to Telelogic Product Support
  Home Downloads Knowledgebase Case Tracking Licensing Help Telelogic Passport
Telelogic TAU (steve huntington)
Decrease font size
Increase font size
Topic Title: How can I generate random number?
Topic Summary: How can I generate random number?
Created On: 5-Jul-2005 01:37
Status: Read Only
Linear : Threading : Single : Branch
Search Topic Search Topic
Topic Tools Topic Tools
Subscribe to this topic Subscribe to this topic
E-mail this topic to someone. E-mail this topic
Bookmark this topic Bookmark this topic
View similar topics View similar topics
View topic in raw text format. Print this topic.
 5-Jul-2005 01:37
User is offline View Users Profile Print this message


Jongil Park

Posts: 4
Joined: 10-Jun-2005

Dear, TAU members

How can I generate random number?

In TAU help file, Any is provide for generating random number. but I don't know how to use it.

GETINTRAND

This macro defines a random generation function, usually rand() or random()

Upper text is extracted from TAU help files. but I cannot find out it TAU.

Best Regards.

Report this to a Moderator Report this to a Moderator
 10-Aug-2005 10:05
User is offline View Users Profile Print this message


Magnus Persson

Posts: 11
Joined: 8-Dec-2003

Integer i;

i=any(Integer);

Hope this helps!
Report this to a Moderator Report this to a Moderator
 16-Aug-2005 13:08
User is offline View Users Profile Print this message


Pieter-Paul Giesberts

Posts: 1
Joined: 16-Aug-2005

If you use it like Magnus suggests, what is the range of numbers from which the random number is generated? Is it possible to limit/change this range? And is it possible to change the random number seed (for example with the current time, or with a fixed value)?
Report this to a Moderator Report this to a Moderator
 17-Aug-2005 12:44
User is offline View Users Profile Print this message


Magnus Persson

Posts: 11
Joined: 8-Dec-2003

You can restrict the range of numbers by using a syntype in the call to any:

----------------------------------------------------------------
syntype restrictedType=Integer constants (0..100);
restrictedType i;

Integer x;
for (x=1;x<100;x++) {
i=any(restrictedType);
{
[[{
char c[100];
sprintf(c, "i: %d\n", #(i));
xPrintString(c);
}
]]
}
}
----------------------------------------------------------

The call to any trnaslates in the end to a call to rand(), so to seed it you may use a call to srand in inline code, something like:

[[srand((unsigned int)clock());]]
Report this to a Moderator Report this to a Moderator
Statistics
20925 users are registered to the Telelogic TAU forum.
There are currently 1 users logged in.
The most users ever online was 15 on 31-Mar-2008 at 16:22.
There are currently 0 guests browsing this forum, which makes a total of 1 users using this forum.
You have posted 0 messages to this forum. 0 overall.

FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.