Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Random numbers in TCL

Status
Not open for further replies.

infi1nity

Programmer
May 13, 2010
5
0
0
GB
I need to generate some random numbers everytime my TCL application is invoked and the value sent to the external system for some kind of auditing purpose. The format of the number must be integer. Is there any command within TCL to this. (The rand command gives random floating point numbers whereas I want some random numbers)
 
You don't say what range your integers must occupy. Assuming there is no constraint and remembering that in Tcl "everything is a string", consider:
Code:
% set a [expr rand()]
0.468741144738
% set b [string range $a 2 end]
468741144738
%
Or, if you prefer:
Code:
% set a [expr rand()]
0.468741144738
% set b [lindex [split $a .] 1]
468741144738
%

_________________
Bob Rashkin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top