-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Generate a random number or randomly select one from multiple numbers #5102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
I have listened to your advice and adopted it , have a nice day |
|
Hi! Just curious — was this PR written with the help of a LLM? |
I designed the API, implemented the logic, wrote the tests, and responded to review feedback manually. That said, like many developers today, I may have used an LLM occasionally for small things |
9romise
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the values generated on the server should also match those rendered on the client-side during the initial render.
Additionally, in my view, useMathRandom (I'd personally prefer useRandom) should behave similarly to other methods in @vueuse/math — staying close to browser APIs.
The current implementation feels a bit custom but only works with numbers.
If it's meant to belong to @vueuse/math, I think its parameters should align with browser APIs; If it's intended as a custom utility, then the parameters shouldn't be limited to just numbers.
Looking forward to hearing other opinions!
You are right. I was thinking today that we should allow strings in multiple choice questions. It shouldn't just be useMathRandom, but more like useRandom. This would fit more scenarios. |
|
I am not sure about setting the value on mounted. Let me try a different approach. |
|
I think we want to have a pseudo |
Thanks for the great suggestion! The seeded PRNG approach is indeed more robust than simply returning fixed values for SSR.Better randomness than fixed values。I will modify the code according to your suggestions and add the following features: 1. Allow users to input a string. 2. When users input an array, allow them to input a second value N, which is used to generate N different random strings. |
|
IMO we should keep it as low level as possible. const {random} = useMathRandom()
console.log(random.value) // i.e. 0.38238We should not provide a start or end value. |
I am not sure what you mean. If you mean the seed, this should not be exposed. It is an internal value that guarantees the first random value on the client and server. |
What I mean is to allow users to input multiple strings and implement random multiple-choice selection, rather than just returning numbers |
I will modify it and return undefined |
I think this should not be part of |
|
How was your day today |
|
@john-li-creater If you agree, I will discuss this internally and, if necessary, make changes to your branch. |
Thank you for reviewing my PR! I really appreciate you taking the time to look at it. Please feel free to make any changes you see fit - I'm happy to collaborate and learn from your suggestions. Looking forward to seeing this feature in vueuse! 🚀 |
Before submitting the PR, please make sure you do the following
fixes #123).Description
Provides a readable Ref for use in Vue composition: when using two parameters, generates a random integer within a closed interval; when using multiple parameters or an array, randomly selects from the candidate values;
Additional context