The purpose is to create a list with N * origSize records identified by "id", the list will contain 3 sets of N records identified by "gNum" and a random number between 1 and origSize. This list allow to sampling with replacement N times any Dataset (each sample same size of original dataset) just by JOIN original.id = list.oldId.

I hope this works better:

IMPORT * FROM ML;
IMPORT * FROM ML.Types;
	t_Index := UNSIGNED4;
	idListRec := RECORD
		t_RecordID id;
		t_RecordID oldId;
	END;
	idListGroupRec := RECORD(idListRec)
		UNSIGNED gNum := 0;
	END;
GenerateNSampleList(t_Index N, t_RecordID origSize) := FUNCTION
	seed := DATASET([{0,0,0}], idListGroupRec);
  PerCluster := ROUNDUP(N*origSize/CLUSTERSIZE);
	idListGroupRec addOffsetId(idListGroupRec L, t_Index c) := TRANSFORM
    SELF.id := (c-1)*PerCluster ;
		SELF.oldid:= 0;
  END;
	// Create and distribute one seed per node
	one_per_node := DISTRIBUTE(NORMALIZE(seed, CLUSTERSIZE, addOffsetId(LEFT, COUNTER)), id DIV PerCluster);
	idListGroupRec fillRec(idListGroupRec L, UNSIGNED4 c) := TRANSFORM
		SELF.id := l.id + c;
		SELF.oldId := RANDOM()%origSize + 1;
		SELF.gNum  := (l.id + c -1) DIV origSize + 1;
	END;
	// Generate records on each node
	// Filter extra nodes generated: (PerCluster * CLUSTERSIZE >= N*origSize) 
	m := NORMALIZE(one_per_node, PerCluster, fillRec(LEFT,COUNTER))(gNum <= N);
	RETURN m;
END;

OUTPUT(GenerateNSampleList(5,25),ALL);