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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

instert random values - need some help

Status
Not open for further replies.

miodzio

Programmer
Aug 6, 2009
2
PL
Hello

I try tu use tcl scrpits during performance tests of my application and I'd like to insert some rows using a few virtual users. Because some of the values must be unique, I need to generate them with a random function. Could you help me and write how to change this part of the script:

set curn4 [oraopen $lda ]
set sql4 "INSERT INTO OSOBY(ID,IMIE,NAZWISKO,STATUS,ID_PRACOWNIKA,LOGIN,TYP_OSOBY) VALUES :)1,:2,:3,:4,:5,:6,:7) "
orasql $curn4 $sql4 -parseonly
orabindexec $curn4 :4 {A} :5 {} :1 {572} :6 {D572} :2 {Bbbbb} :7 {D} :3 {Aa}

to make it put random number values into these two values
:1 {572} :6 {D572} ?
 
To generate random number you can use something like this
random.tcl
Code:
[COLOR=#0000ff]# generate random number between 0 and 1[/color]
[COLOR=#804040][b]set[/b][/color] rand_result [[COLOR=#804040][b]expr[/b][/color] rand()]
[COLOR=#804040][b]puts[/b][/color] [COLOR=#008080]$rand_result[/color]

[COLOR=#0000ff]# create a number form interval 0..1000[/color]
[COLOR=#804040][b]set[/b][/color] rand_integer [[COLOR=#804040][b]expr[/b][/color] round([COLOR=#008080]$rand_result[/color] * [COLOR=#ff00ff]1000[/color])]
[COLOR=#804040][b]puts[/b][/color] [COLOR=#008080]$rand_integer[/color]
[COLOR=#0000ff]#or use format[/color]
[COLOR=#804040][b]set[/b][/color] rand_integer [[COLOR=#804040][b]format[/b][/color] [COLOR=#ff00ff]"%03d"[/color] [[COLOR=#804040][b]expr[/b][/color] round([COLOR=#008080]$rand_result[/color] * [COLOR=#ff00ff]1000[/color])]]
[COLOR=#804040][b]puts[/b][/color] [COLOR=#008080]$rand_integer[/color]
Example Output:
Code:
D:\Work>tclsh85 random.tcl
0.09192434702623838
92
092

However, SQL has a function for generating random numbers between 0 and 1 too, the usage is like
Code:
select RAND(100)     
from SYSIBM.SYSDUMMY1
 
Thank's for these examples. I find them very helpful
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top