Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Pick() random order

Hi,

I need to make a Pick() statement, where the order of the expressions is random every time you reload.

Example:


Load

RecNo() as DoorNo,

Pick(RecNo(),'Car','Goat','Goat') as DoorPrize,

AutoGenerate 3,

DoorNo & '|' & DoorPrize as Door;

should sometimes result in 1|Car 2|Goat 3|Goat, sometimes in 1|Goat 2|Car 3|Goat, and sometimes in 1|Goat 2|Goat 3|Car

Thanks for your help in advance,

Lucas

My actual script:

Load *,

     DoorNo & '|' & DoorPrize as Door;

Load

     RecNo() as DoorNo,

     Pick(RecNo(),'Car','Goat','Goat') as DoorPrize

     AutoGenerate 3;

1 Solution

Accepted Solutions
tresesco
MVP
MVP

Try below code:

Tab1:
Load

     RecNo() As DoorNo,
     Pick(RecNo(),'Car','Goat','Goat') as DoorPrize
     AutoGenerate 3;

Tab2:
Load
       Concat(DoorNo, ';', Rand()) as DoorNo2               // This one is the trick
Resident Tab1;

Let vDoors=Peek('DoorNo2');


Tab3:
Load
SubField('$(vDoors)', ';', RecNo()) & '|' & DoorPrize as Door
Resident  Tab1;

Drop Tables Tab1, Tab2;

It's working.

View solution in original post

14 Replies
tresesco
MVP
MVP

May be using Rand() in your DoorNo expression

Not applicable
Author

If you mean instead of RecNo(), it doesn't work because it takes a value between 0 and 1, and even if I write Ceil(Rand()*3) or whatever, it still would come out as 1|Goat 2|Goat 3|Goat or 1|Car 2|Car 3|Car or etc.. But thanks for the reply!

MK_QSL
MVP
MVP

You can try something like below..

Load *,

     DoorNo & '|' & DoorPrize as Door;

Load

     Pick(Ceil(3*Rand()),1,2,3) as DoorNo,

     Pick(Ceil(3*Rand()),'Car','Goat','Goat') as DoorPrize,

     Ceil(Rand()*3) as Random

AutoGenerate 3;

Not applicable
Author

This gives me (pic), whereas I want 1|(Car or Goat) 2|(Car or Goat) 3|(Car or Goat), where Car appears 1 time and Goat 2 times.

amit_saini
Master III
Master III

Hi Lucas,

This example may help you:

Syntax:

Month:

load * inline [

;

MonthFinal:

LOAD *,

floor(RowNo() * 1) AS Rank

Resident Month;

DROP Table Month;

Output:

Month

Rank

Dec 12

1

Nov  12

2

Jul 12

3

Jun 12

4

May 12

5

Apr 12

6

Mar 12

7

Feb 12

8

Jan 12

9

Thanks,

AS

Not applicable
Author

Thanks for the answer, but I need to know how to sort the expression (Rank in your example) randomly, so it might come out like this:

tresesco
MVP
MVP

Try below code:

Tab1:
Load

     RecNo() As DoorNo,
     Pick(RecNo(),'Car','Goat','Goat') as DoorPrize
     AutoGenerate 3;

Tab2:
Load
       Concat(DoorNo, ';', Rand()) as DoorNo2               // This one is the trick
Resident Tab1;

Let vDoors=Peek('DoorNo2');


Tab3:
Load
SubField('$(vDoors)', ';', RecNo()) & '|' & DoorPrize as Door
Resident  Tab1;

Drop Tables Tab1, Tab2;

It's working.

Not applicable
Author

Hi Lucas,

find here my suggestion:

Mappi:

Mapping LOAD * Inline [

FA, FB

1, Car

2, Goat

3, Goat

];

Load *,

     DoorNo & '|' & DoorPrize as Door;

Load

     RecNo() as DoorNo,

     ApplyMap('Mappi', Ceil(Rand()*10 /4)) as DoorPrize

     AutoGenerate 3     ;

Regards

Roland

Not applicable
Author

Thanks for the reply,

I used your code (only replaced 10/4 by 3) and it works, but someimes I can get 1|Goat 2|Goat 3|Goat or 1|Car 2|Car 3|Car, where Car should only come once and Goat 2 times.

Greetings,

Lucas