Active
Project:
Math Field
Version:
7.x-1.x-dev
Component:
Miscellaneous
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
4 Jul 2015 at 00:15 UTC
Updated:
8 Jul 2015 at 12:16 UTC
Jump to comment: Most recent
Comments
Comment #1
draenen commentedThe module does not yet support random numbers but I think it would be a good feature to add.
Comment #2
jigish.addweb commentedTry the Computed Field module, which allows you to create fields whose values are defined by PHP snippets. For a random number, you might use something like this in your field's "Computed Code" configuration:
$node_field[0]['value'] = rand();Note that
rand()also accepts min and max arguments, in the form ofrand(min, max).Also be sure to enable the "Store using the database settings below" setting with a data type of "int" and a reasonable data length based on the expected range of values for
rand(). This will ensure that the field isn't recomputed every time the node is displayed.NOTES: The above method stores a new random value each time the user updates/resaves the node. If you'd like the field to generate and store a random number once and only once for each node (at the node's initial save), try something like this instead:
This will only set a value for the field if one doesn't already exist.
Let me know if any query regarding this.
Thanks!