
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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;
- « Previous Replies
-
- 1
- 2
- Next Replies »
Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Try below code:
Tab1:
LoadRecNo() 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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
May be using Rand() in your DoorNo expression

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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;

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Try below code:
Tab1:
LoadRecNo() 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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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

- « Previous Replies
-
- 1
- 2
- Next Replies »