How to generate random password using Apex?


Integer len = 10;
Blob blobkey = crypto.generateAesKey(128);
String key = EncodingUtil.convertToHex(blobkey);
String pwd = key.substring(0,len);
system.debug('Random Password-' + pwd);