Of course. But, to counter-nitpick, the OP asked for "the first N
*unique* random floats". Hence distinct.
I might point out, though, that getting floats and truncating them to
two digits is wasting a lot of the processor's time, and yours in
writing it. I'd get integers first and then divide to t
Hi,
I created a Swing-based Clojure environment written in Clojure. It's called
Openar. It's still immature and has basic features necessary for
self-maintaining on Mac OS X only. Yet I hope even this version helps people
who are looking for a casual Clojure box.
Here is the link to the repo:
Has anyone had any experience in the best way to deploy updates to end
users who have no programming experience? The application basically
consists of a src directory, and a bat file which runs 'lein run' to
start the program. It also consists of some extraneous files that have
to be installed on t
On Feb 19, 12:38 am, Alan wrote:
> user=> (take 100 (distinct (repeatedly #(rand-int 200
Nitpick: the distinct call may be useful in some circumstances, but if
you want a truly random sequence, you definitely do not want it there.
Joost.
--
You received this message because you are subscri
Thanks, Alan and Daniel. That is exactly what I was looking for.
On Feb 18, 6:53 pm, Daniel Solano Gomez wrote:
> On Fri Feb 18 15:38 2011, Alan wrote:
>
> > user=> (take 100 (distinct (repeatedly #(rand-int 200
> > (100 55 65 188 90 150 144 72 137 74 187 158 163 28 140 146 111 116 135
> > 88
On Fri Feb 18 15:38 2011, Alan wrote:
> user=> (take 100 (distinct (repeatedly #(rand-int 200
> (100 55 65 188 90 150 144 72 137 74 187 158 163 28 140 146 111 116 135
> 88 29 81 36 173 149 79 16 105 82 162 60 20 49 50 91 176 165 3 56 22 9
> 85 44 101 33 134 186 128 141 103 92 143 123 23 129 83
user=> (take 100 (distinct (repeatedly #(rand-int 200
(100 55 65 188 90 150 144 72 137 74 187 158 163 28 140 146 111 116 135
88 29 81 36 173 149 79 16 105 82 162 60 20 49 50 91 176 165 3 56 22 9
85 44 101 33 134 186 128 141 103 92 143 123 23 129 83 80 5 172 179 166
167 66 195 99 164 38 138 148
I want to get first N (for example 100) unique random floats. Here is
what I have.
(defn rand-flt [max-flt]
(format "%.2f" (rand max-flt)))
(defn gen-rand-flts [max-flt]
(lazy-seq (cons (rand-flt max-flt) (gen-rand-flts max-flt
(defn get-n-floats [max-float, how-many]
(let [tf-fun (f
I want to get first N (for example 100) unique random floats. Here is
what I have.
(defn rand-flt [max-flt]
(format "%.2f" (rand max-flt)))
(defn gen-rand-flts [max-flt]
(lazy-seq (cons (rand-flt max-flt) (gen-rand-flts max-flt
(defn get-n-floats [max-float, how-many]
(let [tf-fun (f
For one, the type of a record is not as malleable as the other attributes of
the record. It's less dynamic.
2011/2/18 Base
> Thank you Stuart! This makes perfect sense and is quite elegant.
>
> So is performance the only compelling reason to do this? I am assuming
> there are times that maps ar
On Fri, Feb 18, 2011 at 5:31 PM, Base wrote:
> Are there some things that you can do with maps that you cannot do
> with defrecord?
Round-trip them through prn/read without them turning into something else.
--
You received this message because you are subscribed to the Google
Groups "Clojure" g
Thank you Stuart! This makes perfect sense and is quite elegant.
So is performance the only compelling reason to do this? I am assuming
there are times that maps are 'good enough', but would you say that if
you ever have a defined data structure you would advise to use
defrecord to gain this incr
For examples of polymorphism mixing Java and Clojure, try my article on
Developer Works:
http://www.ibm.com/developerworks/java/library/j-clojure-protocols/
-Stuart Sierra
clojure.com
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this
Hi Base,
It's easy, because instances of defrecord behave identically to maps. Say
you have a lot of "person" records that look like this:
{:first-name "Stuart", :last-name "Sierra", :location "NYC"}
You might write a constructor function to create these maps:
(defn person [& options]
Hi Stuart -
I am very much still learning Clojure and havent waded into defrecord,
etc.
Could you provide an example of how you wold start with a map and
shift to a defrecord in the future?
Thanks
Base
On Feb 18, 11:16 am, Stuart Sierra
wrote:
> One purpose of defrecord was to be interchangea
> Is there something besides type-hinting that I'm missing?
Is there any chance that you can make a sample data set/complete script
available?
That would make it easier to try different things and figure out where
the problem is.
Sincerely,
Daniel Solano Gómez
pgp40moegLknA.pgp
Description: P
I've actually tried with and without type hinting and end up with
similar performance numbers. I haven't tried type hinting the second
execution.
On Feb 18, 7:49 am, Ken Wesson wrote:
> On Fri, Feb 18, 2011 at 7:03 AM, Daniel Werner
>
>
>
> wrote:
> > On Feb 16, 6:20 am, Nick wrote:
> >> (let
I don't know much about Agent-Based Modeling, but is it possible you could
use Clojure's built-in features, like Agents and Refs, for your application?
The old "ants" demo in Clojure is a simple agent-based simulation.
-Stuart Sierra
clojure.com
--
You received this message because you are su
One purpose of defrecord was to be interchangeable with maps, so that you
can prototype with maps, then switch to defrecord for better performance
without changing much code. If you use constructor functions to create
instances of your records/maps, you hardly have to change anything at all.
A
On Fri, Feb 18, 2011 at 7:03 AM, Daniel Werner
wrote:
> On Feb 16, 6:20 am, Nick wrote:
>> (let [ newv1 (time (doall (map (fn [v u I] (+ ^java.lang.Double v (*
>> 0.5 (+ (* (+ (* 0.04 ^java.lang.Double v) 5) ^java.lang.Double v) 140
>> (- ^java.lang.Double u) ^java.lang.Double I v u I)))
>>
I've made a simple chess engine in Clojure.
This is my first larger program in functional programming so I'd like
to have some feedback about it.
I'd be most interested in ways to make it more idiomatic functional
code.
Also any performance tweaks would be nice. Currently the engine can
search mov
On Feb 16, 6:20 am, Nick wrote:
> (let [ newv1 (time (doall (map (fn [v u I] (+ ^java.lang.Double v (*
> 0.5 (+ (* (+ (* 0.04 ^java.lang.Double v) 5) ^java.lang.Double v) 140
> (- ^java.lang.Double u) ^java.lang.Double I v u I)))
> newv (time (doall (map (fn [v u I] (+ v (* 0.5 (+ (
22 matches
Mail list logo