I have several decimal fields on various content types. I need to multiply one of those values by a random number in a range of numbers. For instance, one content type may have a field with a value of 50. It needs to be multiplied by a value between 6% and 12% (so, between 1.06 and 1.12). I'd like to store this numerical range in a field on a node. I've got the entirety of what I need to do, data comparison, storing the result in a variable, rewriting the field based on the results of the variable, etc, down for static numbers. Just not sure how to go about it with a "random" decimal in a range, as listed above.
Any ideas on how I might solve this? Is there a way to provide two fields on the entity, like "Min Value" and "Max Value" (in my example, min_value would be 1.06 and max_value would be 1.12) and somehow have rules select a decimal between that range randomly? If necessary, with a little guidance, I might be able to write an action for this, but I'm not even sure where to begin. Or is there another solution I've missed?
Comments
Comment #1
mitchell CreditAttribution: mitchell commentedThere is an, mt_rand based, generate_string action, but it would need min and max parameters added.
Comment #2
Anthony Pero CreditAttribution: Anthony Pero commentedI was recently looking at Rules Bonus Pack. The D6 version actually HAS an integer randomizer in it, but it was not ported to D7. Wish I knew more PHP.
Comment #3
TR CreditAttribution: TR commentedYes, this would be simple with a custom action, and the link in #1 gives you source code for a very similar action. Or, there is a random number action in Rules Bonus Pack which was ported to D7. This is not a feature that would be included in Rules.