You need to sign in to do that
Don't have an account?
Veena Gopal
Units_Sold__c = (Double)(10*Math.random()+1));
In Apex workbook in page 52, they have assigned a value to the field as below.
Units_Sold__c = (Double)(10*Math.random()+1));
what does this mean? what value will be stored in the field Units_Sold__c?
Units_Sold__c = (Double)(10*Math.random()+1));
what does this mean? what value will be stored in the field Units_Sold__c?
Returns a positive Double that is greater than or equal to 0.0 and less than 1.0.
1) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_math.htm
So Random number will give number from 0.0 to 1.0 .
* 10 means 0 to leass then 10.
Then +1 means 1 to less the 11 ( means 10.999)
You can simply execute the same code in Developer console and Workbench to see the result.
All Answers
Math.random() is a random number generator. It returns any random decimal number between 0.0 to less than 0.1.
Now (10 * Math.random()) gives some double numbers between 0 - 10. so 10*Math.random()+1 gives 1 - 10.9.
Hope it helps.
Thanks and Regards,
Shiva RV
Returns a positive Double that is greater than or equal to 0.0 and less than 1.0.
1) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_math.htm
So Random number will give number from 0.0 to 1.0 .
* 10 means 0 to leass then 10.
Then +1 means 1 to less the 11 ( means 10.999)
You can simply execute the same code in Developer console and Workbench to see the result.