* org table: one column of random numbers (but natural ones) @ 2020-05-27 20:40 Uwe Brauer 2020-05-28 6:06 ` tbanelwebmin ` (2 more replies) 0 siblings, 3 replies; 9+ messages in thread From: Uwe Brauer @ 2020-05-27 20:40 UTC (permalink / raw) To: emacs-orgmode Hi I have a org table and want to add a new colum, which natural numbers which are randomly ordered So I tried #+TBLFM: $1=@#-1::$4=random($1@4);f1 But the column contains real numbers What can I do Uwe Brauer ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: org table: one column of random numbers (but natural ones) 2020-05-27 20:40 org table: one column of random numbers (but natural ones) Uwe Brauer @ 2020-05-28 6:06 ` tbanelwebmin 2020-05-28 18:25 ` Uwe Brauer 2020-05-28 7:54 ` org table: one column of random numbers (but natural ones) Eric S Fraga 2020-05-28 7:56 ` Eric S Fraga 2 siblings, 1 reply; 9+ messages in thread From: tbanelwebmin @ 2020-05-28 6:06 UTC (permalink / raw) To: emacs-orgmode Le 27/05/2020 à 22:40, Uwe Brauer a écrit : > Hi > > > I have a org table and want to add a new colum, which natural numbers > which are randomly ordered > > So I tried > > #+TBLFM: $1=@#-1::$4=random($1@4);f1 > > But the column contains real numbers > > What can I do > > Uwe Brauer > > What about: #+TBLFM: $4=random($1);f0 In row 67 you would have a random integer in the range [0..67) f0 format removes any fractional part leaving only an integer number ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: org table: one column of random numbers (but natural ones) 2020-05-28 6:06 ` tbanelwebmin @ 2020-05-28 18:25 ` Uwe Brauer 2020-05-28 20:26 ` Stig Brautaset 0 siblings, 1 reply; 9+ messages in thread From: Uwe Brauer @ 2020-05-28 18:25 UTC (permalink / raw) To: emacs-orgmode [-- Attachment #1: Type: text/plain, Size: 478 bytes --] > Le 27/05/2020 à 22:40, Uwe Brauer a écrit : > What about: > #+TBLFM: $4=random($1);f0 > In row 67 you would have a random integer in the range [0..67) > f0 format removes any fractional part leaving only an integer number Aha thanks, a minor thing, which I thank, cannot be really done: Is it possible to avoid number repetition? So I want a random sequence of the column 67 but I don't want numbers to be repeated. Regards Uwe [-- Attachment #2: smime.p7s --] [-- Type: application/pkcs7-signature, Size: 5673 bytes --] ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: org table: one column of random numbers (but natural ones) 2020-05-28 18:25 ` Uwe Brauer @ 2020-05-28 20:26 ` Stig Brautaset 2020-05-29 11:19 ` [random sorting] (was: org table: one column of random numbers (but natural ones)) Uwe Brauer 0 siblings, 1 reply; 9+ messages in thread From: Stig Brautaset @ 2020-05-28 20:26 UTC (permalink / raw) To: Uwe Brauer, emacs-orgmode > > In row 67 you would have a random integer in the range [0..67) > > f0 format removes any fractional part leaving only an integer number > > Aha thanks, a minor thing, which I thank, cannot be really done: > > Is it possible to avoid number repetition? > > So I want a random sequence of the column 67 but I don't want numbers to > be repeated. To avoid duplicates you could generate a sequence from [0..67), shuffle it[1], then use the row number as an index into that list. (Or pop off the front.) How to do that from an org table function I have no idea, however. [1]: Emacs lisp "Knuth shuffle" implementation: https://stackoverflow.com/a/49505968/5950 Regards, Stig ^ permalink raw reply [flat|nested] 9+ messages in thread
* [random sorting] (was: org table: one column of random numbers (but natural ones)) 2020-05-28 20:26 ` Stig Brautaset @ 2020-05-29 11:19 ` Uwe Brauer 2020-05-29 11:43 ` [random sorting] Eric S Fraga 2020-05-29 16:52 ` [random sorting] (was: org table: one column of random numbers (but natural ones)) Stig Brautaset 0 siblings, 2 replies; 9+ messages in thread From: Uwe Brauer @ 2020-05-29 11:19 UTC (permalink / raw) To: emacs-orgmode [-- Attachment #1: Type: text/plain, Size: 925 bytes --] >>> "SB" == Stig Brautaset <stig@brautaset.org> writes: >> > In row 67 you would have a random integer in the range [0..67) >> > f0 format removes any fractional part leaving only an integer number >> >> Aha thanks, a minor thing, which I thank, cannot be really done: >> >> Is it possible to avoid number repetition? >> >> So I want a random sequence of the column 67 but I don't want numbers to >> be repeated. > To avoid duplicates you could generate a sequence from [0..67), shuffle > it[1], then use the row number as an index into that list. (Or pop off the > front.) How to do that from an org table function I have no idea, > however. Thanks I tried in a row of 33 $5=random([0..34]);f0 $5=random([0..34));f0 $5=random([0..33));f0 But random repeats, however org-table-sort-lines sorts anyway And what I truly needed is a random sorting of sorts. [-- Attachment #2: smime.p7s --] [-- Type: application/pkcs7-signature, Size: 5673 bytes --] ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [random sorting] 2020-05-29 11:19 ` [random sorting] (was: org table: one column of random numbers (but natural ones)) Uwe Brauer @ 2020-05-29 11:43 ` Eric S Fraga 2020-05-29 16:52 ` [random sorting] (was: org table: one column of random numbers (but natural ones)) Stig Brautaset 1 sibling, 0 replies; 9+ messages in thread From: Eric S Fraga @ 2020-05-29 11:43 UTC (permalink / raw) To: emacs-orgmode On Friday, 29 May 2020 at 13:19, Uwe Brauer wrote: > But random repeats, however org-table-sort-lines sorts anyway > And what I truly needed is a random sorting of sorts. (now that I am awake... ;-)) What you want is a "permutation" vector. Calc does appear to have some support for permutation vectors but I'm not sure it has what you need to create a random permutation. -- : Eric S Fraga via Emacs 28.0.50, Org release_9.3.6-640-g9bc0cc ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [random sorting] (was: org table: one column of random numbers (but natural ones)) 2020-05-29 11:19 ` [random sorting] (was: org table: one column of random numbers (but natural ones)) Uwe Brauer 2020-05-29 11:43 ` [random sorting] Eric S Fraga @ 2020-05-29 16:52 ` Stig Brautaset 1 sibling, 0 replies; 9+ messages in thread From: Stig Brautaset @ 2020-05-29 16:52 UTC (permalink / raw) To: Uwe Brauer, emacs-orgmode Uwe Brauer <oub@mat.ucm.es> writes: >>>> "SB" == Stig Brautaset <stig@brautaset.org> writes: > > >> > In row 67 you would have a random integer in the range [0..67) > >> > f0 format removes any fractional part leaving only an integer number > >> > >> Aha thanks, a minor thing, which I thank, cannot be really done: > >> > >> Is it possible to avoid number repetition? > >> > >> So I want a random sequence of the column 67 but I don't want numbers to > >> be repeated. > > > To avoid duplicates you could generate a sequence from [0..67), shuffle > > it[1], then use the row number as an index into that list. (Or pop off the > > front.) How to do that from an org table function I have no idea, > > however. > > Thanks I tried in a row of 33 > $5=random([0..34]);f0 > $5=random([0..34));f0 > $5=random([0..33));f0 > > But random repeats, however org-table-sort-lines sorts anyway > And what I truly needed is a random sorting of sorts. Right, I think I failed to make myself understood so here's an example of what I had in mind. It's not convenient to use (need to execute a source code block) but hopefully what I mean is a bit clearer, and someone can clean it up a little :-) First we need to generate a randomised sequence of unique integer in a range, using the Knuth shuffle I pointed to earlier. Every time you run tihs you get a new sequence. I've kept the output more to verify that the results have unique output, as the table formula later will read from the lisp variable, IIUC. #+name: random-seq #+begin_src emacs-lisp :var length=10 :results list (defun nshuffle (sequence) (loop for i from (length sequence) downto 2 do (rotatef (elt sequence (random i)) (elt sequence (1- i)))) sequence) (setq random-seq (nshuffle (number-sequence 0 (1- length)))) #+end_src #+RESULTS: random-seq - 5 - 9 - 6 - 0 - 7 - 8 - 3 - 2 - 1 - 4 And now for the table that uses the variable. As we compute the randomised sequence ahead of time for each invocation of the column formula, and we can use each row number as an index into the sequence to assign a unique, randomised integer from a range to each column. | 0 | 5 | | 1 | 9 | | 2 | 6 | | 3 | 0 | | 4 | 7 | | 5 | 8 | | 6 | 3 | | 7 | 2 | | 8 | 1 | | 9 | 4 | #+TBLFM: $2='(nth (string-to-number $1) random-seq) Possible improvements (that I don't think I'm up to making): 1. Don't require the column of indices to use as index into the sequence 2. Show how to do this without having the separate pre-compute step of the index (possibly with memoizing a sequence on first use?) Hope this helps! Regards, Stig ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: org table: one column of random numbers (but natural ones) 2020-05-27 20:40 org table: one column of random numbers (but natural ones) Uwe Brauer 2020-05-28 6:06 ` tbanelwebmin @ 2020-05-28 7:54 ` Eric S Fraga 2020-05-28 7:56 ` Eric S Fraga 2 siblings, 0 replies; 9+ messages in thread From: Eric S Fraga @ 2020-05-28 7:54 UTC (permalink / raw) To: emacs-orgmode On Wednesday, 27 May 2020 at 22:40, Uwe Brauer wrote: > I have a org table and want to add a new colum, which natural numbers > which are randomly ordered Something like #+TBLFM: $1=floor(100*random(0.1)) I don't know what argument you want to pass to random(), especially as you had $1@4 which seems wrong? -- : Eric S Fraga via Emacs 28.0.50, Org release_9.3.6-640-g9bc0cc ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: org table: one column of random numbers (but natural ones) 2020-05-27 20:40 org table: one column of random numbers (but natural ones) Uwe Brauer 2020-05-28 6:06 ` tbanelwebmin 2020-05-28 7:54 ` org table: one column of random numbers (but natural ones) Eric S Fraga @ 2020-05-28 7:56 ` Eric S Fraga 2 siblings, 0 replies; 9+ messages in thread From: Eric S Fraga @ 2020-05-28 7:56 UTC (permalink / raw) To: emacs-orgmode Ignore previous reply. I misread your email. Too early in the morning for me. -- : Eric S Fraga via Emacs 28.0.50, Org release_9.3.6-640-g9bc0cc ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2020-05-29 16:52 UTC | newest] Thread overview: 9+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2020-05-27 20:40 org table: one column of random numbers (but natural ones) Uwe Brauer 2020-05-28 6:06 ` tbanelwebmin 2020-05-28 18:25 ` Uwe Brauer 2020-05-28 20:26 ` Stig Brautaset 2020-05-29 11:19 ` [random sorting] (was: org table: one column of random numbers (but natural ones)) Uwe Brauer 2020-05-29 11:43 ` [random sorting] Eric S Fraga 2020-05-29 16:52 ` [random sorting] (was: org table: one column of random numbers (but natural ones)) Stig Brautaset 2020-05-28 7:54 ` org table: one column of random numbers (but natural ones) Eric S Fraga 2020-05-28 7:56 ` Eric S Fraga
Code repositories for project(s) associated with this public inbox https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).