Re: [pmwiki-users] Random PTVs set with {(randk)} do not retain set values
Thank you Hans, Randy, Petko and Chris for your helpful answers. Petko's solution ended up to be (for me) the most practical and straightforward to adopt. It just works. And no, Petko, thank you, I just need random strings of a fixed length. Actually, as I am using Fox forms, Hans' answer could perhaps have been the best, most flexible idea, yet I could not manage to let it work on my pages. My fault. Again thanks! Luigi ___ pmwiki-users mailing list pmwiki-users@pmichaud.com http://www.pmichaud.com/mailman/listinfo/pmwiki-users
Re: [pmwiki-users] Random PTVs set with {(randk)} do not retain set values
On 2014-12-14 01:20, ki...@kirpi.it wrote: If I set a PTV to a random value with {(randk)}[1], say Random_string: {(randk 7)} I then would like that specific PTV to retain its value. Instead, {$:Random_string} gets every time a new random value. I am perhaps just misunderstanding the way PTVs are working; When you write into a page {$:Random_string}, it will be replaced with the wikitext content after the Random_string: definition, and evaluated later. To PmWiki, it is the same if you paste more than once {$:Random_string} or {(randk 7)}. So the {(randk 7)} expression will be evaluated every time. nonetheless I am trying to find a way to freeze PTV random values once they are set, in order to use them in pages and formulas. This can be done with a custom page variable defined in config.php: $FmtPV['$Randk7'] = 'randomkeys(7)'; # evaluated every time -OR- $FmtPV['$Randk7'] = ''. randomkeys(7) . ''; # evaluated once and freezed until the page is reloaded Then in the wiki page use {$Randk7}. (this uses the function suggested in the MarkupExpressionSamples page) This is obviously not very handy if you need to have many different such variables of different length in the pages. Do you need many lengths? Petko ___ pmwiki-users mailing list pmwiki-users@pmichaud.com http://www.pmichaud.com/mailman/listinfo/pmwiki-users
Re: [pmwiki-users] Random PTVs set with {(randk)} do not retain set values
You can use a page variable to do this. For example, in a configuration file: $RandomNum = mt_rand(1,100); $FmtPV['$RandomNum'] = '$RandomNum'; Then in markup use: {$RandomNum} Or if you must use a PTV, use: MyPTV: {$RandomNum} Randy {$:Random_string} ... I am trying to find a way to freeze PTV random values once they are set, in order to use them in pages and formulas. ___ pmwiki-users mailing list pmwiki-users@pmichaud.com http://www.pmichaud.com/mailman/listinfo/pmwiki-users
Re: [pmwiki-users] Random PTVs set with {(randk)} do not retain set values
Hello Luigi, sorry, got your pmwiki list message only now (something wrong with the list server I suppose) Sunday, December 14, 2014, 12:20:56 AM, you wrote: If I set a PTV to a random value with {(randk)}[1], say Random_string: {(randk 7)} I then would like that specific PTV to retain its value. Instead, {$:Random_string} gets every time a new random value. if you write into the page: Random_string: {(randk 7)} then the PTV 'Random_string' always has the value '{(randk 7)}' i.e. the markup expression. And as you see, it changes each time you open the page, or refresh it. so to have a random number 'fixed' as a PTV value, you would need to post it, for instance with Fox. So in the fox form you need something like this: (:input hidden $:Random_string={$$(randk 7)}:) Then the markup expression will be evaluated when the form gets processed, and assigned to the Random_string PTV. Or use in the fox form: (:input hidden $:Random_string={(randk 7)}:) then the markup expression will be evaluated when th epag eis displayed, and on posting the value will be assigned to the PTV. for a random number it probably does not matter when th emarkup expression gets evaluated, at the time of form processing or th etime of page display, but for other expressions it may be crucial, for instance to post a time stamp. hope this helps! Best, Hans ___ pmwiki-users mailing list pmwiki-users@pmichaud.com http://www.pmichaud.com/mailman/listinfo/pmwiki-users
Re: [pmwiki-users] Random PTVs set with {(randk)} do not retain set values
Ptv like most things pmwiki will simply get evaluated like a macro. Which can be powerful for some things. Thus you never set a var to the value of a func. The value is the func in most cases. Sent on the new Sprint Network - Reply message - From: ki...@kirpi.it ki...@kirpi.it To: PmWiki Users pmwiki-users@pmichaud.com Subject: [pmwiki-users] Random PTVs set with {(randk)} do not retain set values Date: Sat, Dec 13, 2014 6:20 PM If I set a PTV to a random value with {(randk)}[1], say Random_string: {(randk 7)} I then would like that specific PTV to retain its value. Instead, {$:Random_string} gets every time a new random value. I am perhaps just misunderstanding the way PTVs are working; nonetheless I am trying to find a way to freeze PTV random values once they are set, in order to use them in pages and formulas. Thanks for any hint :-) Luigi [1] http://www.pmwiki.org/wiki/Cookbook/MarkupExpressionSamples ___ pmwiki-users mailing list pmwiki-users@pmichaud.com http://www.pmichaud.com/mailman/listinfo/pmwiki-users___ pmwiki-users mailing list pmwiki-users@pmichaud.com http://www.pmichaud.com/mailman/listinfo/pmwiki-users