How to randomize enumerated data type?

In reply to dave_59:

below code is an excerpt from my sequencer.

package RFile_parameters;
typedef enum { READ, WRITE, RD_WR } RFile_mode_e ;
endpackage

import RFile_parameters::*;
class RFile_transaction extends uvm_sequence_item;
rand RFile_mode_e mode;

endclass:RFile_transaction

class RFile_sequence extends uvm_sequence#(RFile_transaction);
`uvm_object_utils(RFile_sequence)
function new(string name = “”);
super.new(name);
endfunction
task body();

RFile_tr.randomize()
RFile_transaction RFile_tr;
RFile_tr = RFile_transaction::type_id::create( .name(“RFile_tr”), .contxt(get_full_name()) );
start_item(RFile_tr);
assert ( RFile_tr.randomize() );

endtask

endclass

while randomizing the transaction, mode is always holding the first element of enum data type RFile_mode_e. In this case “READ”. When I changed the order in RFile_mode_e, mode was holding again the first element which was “WRITE”. Not sure where I went wrong.