generating random number in a specified range

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

kirankota79
Premium Member
Premium Member
Posts: 315
Joined: Tue Oct 31, 2006 3:38 pm

generating random number in a specified range

Post 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.........
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

You dont need a routine for that. Read Vincents FAQ Entryfor that.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

I missed the "Random numbers" point in your post. What are you trying to achieve exactly?
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
kirankota79
Premium Member
Premium Member
Posts: 315
Joined: Tue Oct 31, 2006 3:38 pm

Post 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.................
trobinson
Participant
Posts: 208
Joined: Thu Apr 11, 2002 6:02 am
Location: Saint Louis
Contact:

Post 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.
kirankota79
Premium Member
Premium Member
Posts: 315
Joined: Tue Oct 31, 2006 3:38 pm

Post by kirankota79 »

can u please be more clear.....iam using colmn generator but it is generating the numbers serially starting from 0 not randomly.
trobinson
Participant
Posts: 208
Joined: Thu Apr 11, 2002 6:02 am
Location: Saint Louis
Contact:

Post by trobinson »

Instead of cycle select random from the Column Metadata window. Set the limit to 10000. It starts at 0 I believe.
kirankota79
Premium Member
Premium Member
Posts: 315
Joined: Tue Oct 31, 2006 3:38 pm

Post 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.
trobinson
Participant
Posts: 208
Joined: Thu Apr 11, 2002 6:02 am
Location: Saint Louis
Contact:

Post 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.
kirankota79
Premium Member
Premium Member
Posts: 315
Joined: Tue Oct 31, 2006 3:38 pm

Post by kirankota79 »

it is working.......but it is repeating some numbers......how i can avoid this?
kirankota79
Premium Member
Premium Member
Posts: 315
Joined: Tue Oct 31, 2006 3:38 pm

Post 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?
pbatchu
Charter Member
Charter Member
Posts: 20
Joined: Thu Aug 17, 2006 11:53 am
Location: Boise

Post 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
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post 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?
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
kirankota79
Premium Member
Premium Member
Posts: 315
Joined: Tue Oct 31, 2006 3:38 pm

Post 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.
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post 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.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
Post Reply