Page 1 of 2

generating random number in a specified range

Posted: Wed Mar 14, 2007 11:40 am
by kirankota79
can anybody has c++ routine that takes total row count and generate random numbers in that range and should go to the output of the transformer. Or is there any other way to get it.....


any hints plz.........

Posted: Wed Mar 14, 2007 11:42 am
by DSguru2B
You dont need a routine for that. Read Vincents FAQ Entryfor that.

Posted: Wed Mar 14, 2007 11:55 am
by DSguru2B
I missed the "Random numbers" point in your post. What are you trying to achieve exactly?

Posted: Wed Mar 14, 2007 12:08 pm
by kirankota79
for example: i got a total row count as 10000. I should be able to generate random numbers from 1 to 10000 which should be unique......should not be repeated. for example it may look

rowid randomrowid

1 566
2 492
3 9999
4 10000
5 892
. .
. .
. .
10000 1

and so on.................

Posted: Wed Mar 14, 2007 12:12 pm
by trobinson
Have you tried a column generator cycling from 1 to 10000 generating a random number? It could be inserted directly downstream of the Transformer.

Posted: Wed Mar 14, 2007 12:37 pm
by kirankota79
can u please be more clear.....iam using colmn generator but it is generating the numbers serially starting from 0 not randomly.

Posted: Wed Mar 14, 2007 12:50 pm
by trobinson
Instead of cycle select random from the Column Metadata window. Set the limit to 10000. It starts at 0 I believe.

Posted: Wed Mar 14, 2007 1:12 pm
by kirankota79
iam sorry......i donno regarding which stage u r talking. i cant see anything in the column metadata of this stage to select as random and to set the value.

Posted: Wed Mar 14, 2007 1:22 pm
by trobinson
No problem. It is a pain. I assume you have a Column Generator in your job? From the columns tab, highlight the field that is cycling. Using your mouse , double click the number to the right of the column name.

This should bring up the Edit Column MetaData window.

The bottom middle box should be properties. the Type List dropdown to the right of that should be set to cycle. Change it to random.

Add Limit as an available property. Set to 10000.

Select the help button if this is not as clear as an unmuddied lake.

Posted: Wed Mar 14, 2007 1:30 pm
by kirankota79
it is working.......but it is repeating some numbers......how i can avoid this?

Posted: Wed Mar 14, 2007 1:32 pm
by kirankota79
one more thing.......i cant predict the row count.....i comes as an input to the column generator. so i cant set the limit manually.........how i solve this problem?

Posted: Wed Mar 14, 2007 2:38 pm
by pbatchu
You can use a transformer to increment the value. Use initial value, rownum if it is server job, combination of partition number, initial value and rownum to get unique number in parallel job.

- Pavan

Posted: Wed Mar 14, 2007 2:41 pm
by DSguru2B
You have to provide the rowcount initially as a parameter to the job.
Pavan- The method you advised will create a sequential number. The OP is interested in random numbers.
May I ask why you need random numbers?

Posted: Wed Mar 14, 2007 5:40 pm
by kirankota79
i want to do a swap of rows. so that the records are placed in the random rowid instead of the original one. this is a kind of masking iam doing.

Posted: Wed Mar 14, 2007 6:12 pm
by DSguru2B
If its just a few records, build a server job, load a hashed file and then re-load it into a flat file. Records are randomly distributed in a hashed file.