Skip to main content
Commonmark migration
Source Link

#05AB1E, 23 22 bytes

05AB1E, 23 22 bytes

[тε5°x<Ýs/<Ω}DnOtDî#}/ 

Implements the 2nd algorithm.

Try it online or get a few more random outputs.

Explanation:

NOTE: 05AB1E doesn't have a builtin to get a random decimal value in the range \$[0,1)\$. Instead, I create a list in increments of \$0.00001\$, and pick random values from that list. This increment could be changed to \$0.000000001\$ by changing the 5 to 9 in the code (although it would become rather slow..).

[ # Start an infinite loop: тε # Push 100, and map (basically, create a list with 3 values): 5° # Push 100,000 (10**5) x # Double it to 200,000 (without popping) < # Decrease it by 1 to 199,999 Ý # Create a list in the range [0, 199,999] s/ # Swap to get 100,000 again, and divide each value in the list by this < # And then decrease by 1 to change the range [0,2) to [-1,1) Ω # And pop and push a random value from this list } # After the map, we have our three random values D # Duplicate this list n # Square each inner value O # Take the sum of these squares t # Take the square-root of that D # Duplicate that as well î # Ceil it, and if it's now exactly 1: # # Stop the infinite loop }/ # After the infinite loop: normalize by dividing # (after which the result is output implicitly) 

#05AB1E, 23 22 bytes

[тε5°x<Ýs/<Ω}DnOtDî#}/ 

Implements the 2nd algorithm.

Try it online or get a few more random outputs.

Explanation:

NOTE: 05AB1E doesn't have a builtin to get a random decimal value in the range \$[0,1)\$. Instead, I create a list in increments of \$0.00001\$, and pick random values from that list. This increment could be changed to \$0.000000001\$ by changing the 5 to 9 in the code (although it would become rather slow..).

[ # Start an infinite loop: тε # Push 100, and map (basically, create a list with 3 values): 5° # Push 100,000 (10**5) x # Double it to 200,000 (without popping) < # Decrease it by 1 to 199,999 Ý # Create a list in the range [0, 199,999] s/ # Swap to get 100,000 again, and divide each value in the list by this < # And then decrease by 1 to change the range [0,2) to [-1,1) Ω # And pop and push a random value from this list } # After the map, we have our three random values D # Duplicate this list n # Square each inner value O # Take the sum of these squares t # Take the square-root of that D # Duplicate that as well î # Ceil it, and if it's now exactly 1: # # Stop the infinite loop }/ # After the infinite loop: normalize by dividing # (after which the result is output implicitly) 

05AB1E, 23 22 bytes

[тε5°x<Ýs/<Ω}DnOtDî#}/ 

Implements the 2nd algorithm.

Try it online or get a few more random outputs.

Explanation:

NOTE: 05AB1E doesn't have a builtin to get a random decimal value in the range \$[0,1)\$. Instead, I create a list in increments of \$0.00001\$, and pick random values from that list. This increment could be changed to \$0.000000001\$ by changing the 5 to 9 in the code (although it would become rather slow..).

[ # Start an infinite loop: тε # Push 100, and map (basically, create a list with 3 values): 5° # Push 100,000 (10**5) x # Double it to 200,000 (without popping) < # Decrease it by 1 to 199,999 Ý # Create a list in the range [0, 199,999] s/ # Swap to get 100,000 again, and divide each value in the list by this < # And then decrease by 1 to change the range [0,2) to [-1,1) Ω # And pop and push a random value from this list } # After the map, we have our three random values D # Duplicate this list n # Square each inner value O # Take the sum of these squares t # Take the square-root of that D # Duplicate that as well î # Ceil it, and if it's now exactly 1: # # Stop the infinite loop }/ # After the infinite loop: normalize by dividing # (after which the result is output implicitly) 
forgot to remove something in the explanation
Source Link
Kevin Cruijssen
  • 136.3k
  • 14
  • 155
  • 394
[  # Start an infinite loop: тε  # Push 100, and map (basically, create a list with 3 values): 5°  # Push 100,000 (10**5)   ©  #  Store it in variable `®` (without popping) x # Double it to 200,000 (without popping)   < # Decrease it by 1 to 199,999   Ý # Create a list in the range [0, 199,999]   s/ # Swap to get 100,000 again, and divide each value in the list by this   < # And then decrease by 1 to change the range [0,2) to [-1,1)   Ω # And pop and push a random value from this list }  # After the map, we have our three random values D  # Duplicate this list n  # Square each inner value O  # Take the sum of these squares t  # Take the square-root of that D  # Duplicate that as well î  # Ceil it, and if it's now exactly 1: #  # Stop the infinite loop }/  # After the infinite loop: normalize by dividing   # (after which the result is output implicitly) 
[  # Start an infinite loop: тε  # Push 100, and map (basically, create a list with 3 values): 5°  # Push 100,000 (10**5)   ©  #  Store it in variable `®` (without popping) x # Double it to 200,000 (without popping)   < # Decrease it by 1 to 199,999   Ý # Create a list in the range [0, 199,999]   s/ # Swap to get 100,000 again, and divide each value in the list by this   < # And then decrease by 1 to change the range [0,2) to [-1,1)   Ω # And pop and push a random value from this list }  # After the map, we have our three random values D  # Duplicate this list n  # Square each inner value O  # Take the sum of these squares t  # Take the square-root of that D  # Duplicate that as well î  # Ceil it, and if it's now exactly 1: #  # Stop the infinite loop }/  # After the infinite loop: normalize by dividing   # (after which the result is output implicitly) 
[ # Start an infinite loop: тε # Push 100, and map (basically, create a list with 3 values): 5° # Push 100,000 (10**5) x # Double it to 200,000 (without popping) < # Decrease it by 1 to 199,999 Ý # Create a list in the range [0, 199,999] s/ # Swap to get 100,000 again, and divide each value in the list by this < # And then decrease by 1 to change the range [0,2) to [-1,1) Ω # And pop and push a random value from this list } # After the map, we have our three random values D # Duplicate this list n # Square each inner value O # Take the sum of these squares t # Take the square-root of that D # Duplicate that as well î # Ceil it, and if it's now exactly 1: # # Stop the infinite loop }/ # After the infinite loop: normalize by dividing # (after which the result is output implicitly) 
added 15 characters in body
Source Link
Kevin Cruijssen
  • 136.3k
  • 14
  • 155
  • 394

#05AB1E, 23 23 22 bytes

[тε5°x<Ýs/<Ω}DnOtD1‹#DnOtDî#}/ 

Try it onlineTry it online or get a few more random outputsget a few more random outputs.

[ # Start an infinite loop: тε # Push 100, and map (basically, create a list with 3 values): 5° # Push 100,000 (10**5) © # Store it in variable `®` (without popping) x # Double it to 200,000 (without popping) < # Decrease it by 1 to 199,999 Ý # Create a list in the range [0, 199,999] s/ # Swap to get 100,000 again, and divide each value in the list by this < # And then decrease by 1 to change the range [0,2) to [-1,1) Ω # And pop and push a random value from this list } # After the map, we have our three random values D # Duplicate this list n # Square each inner value O # Take the sum of these squares t # Take the square-root of that D # Duplicate that as well 1‹î  # IfCeil it, and if it's smallernow thanexactly 1:   #  # Stop the infinite loop }/ # After the infinite loop: normalize by dividing # (after which the result is output implicitly) 

#05AB1E, 23 bytes

[тε5°x<Ýs/<Ω}DnOtD1‹#}/ 

Try it online or get a few more random outputs.

[ # Start an infinite loop: тε # Push 100, and map (basically, create a list with 3 values): 5° # Push 100,000 (10**5) © # Store it in variable `®` (without popping) x # Double it to 200,000 (without popping) < # Decrease it by 1 to 199,999 Ý # Create a list in the range [0, 199,999] s/ # Swap to get 100,000 again, and divide each value in the list by this < # And then decrease by 1 to change the range [0,2) to [-1,1) Ω # And pop and push a random value from this list } # After the map, we have our three random values D # Duplicate this list n # Square each inner value O # Take the sum of these squares t # Take the square-root of that D # Duplicate that as well 1‹ # If it's smaller than 1:   # # Stop the infinite loop }/ # After the infinite loop: normalize by dividing # (after which the result is output implicitly) 

#05AB1E, 23 22 bytes

[тε5°x<Ýs/<Ω}DnOtDî#}/ 

Try it online or get a few more random outputs.

[ # Start an infinite loop: тε # Push 100, and map (basically, create a list with 3 values): 5° # Push 100,000 (10**5) © # Store it in variable `®` (without popping) x # Double it to 200,000 (without popping) < # Decrease it by 1 to 199,999 Ý # Create a list in the range [0, 199,999] s/ # Swap to get 100,000 again, and divide each value in the list by this < # And then decrease by 1 to change the range [0,2) to [-1,1) Ω # And pop and push a random value from this list } # After the map, we have our three random values D # Duplicate this list n # Square each inner value O # Take the sum of these squares t # Take the square-root of that D # Duplicate that as well î  # Ceil it, and if it's now exactly 1: #  # Stop the infinite loop }/ # After the infinite loop: normalize by dividing # (after which the result is output implicitly) 
Post Undeleted by Kevin Cruijssen
fixed
Source Link
Kevin Cruijssen
  • 136.3k
  • 14
  • 155
  • 394
Loading
Post Deleted by Kevin Cruijssen
added 365 characters in body
Source Link
Kevin Cruijssen
  • 136.3k
  • 14
  • 155
  • 394
Loading
Source Link
Kevin Cruijssen
  • 136.3k
  • 14
  • 155
  • 394
Loading